MAC python3.7+django2+ uwsgi2.0

  1. 安裝python3.7

參考資料:https://www.cnblogs.com/1009-smile/p/8005524.html

就是一鍵安裝,很簡單

下載鏈接:https://www.python.org/downloads/

  1. 安裝django2.0

參考資料:http://www.runoob.com/django/django-install.html

Django 版本對應的 Python 版本

如果是python2.0+,需要使用easy_install安裝pip(easy_install是Python的包管理工具,類似Ruby下的gem,pip是升級版的easy_install)

sudo easy_install pip

但是我們安裝的是python3,它自帶pip3,直接使用

sudo pip3 install Django

查看版本,確認是否能正常使用

django-admin --version

2.0.7

查看安裝位置

which django-admin

/Library/Frameworks/Python.framework/Versions/3.7/bin/django-admin
測試django是否能正常使用
在任意文件夾下,執(zhí)行

django-admin startproject HelloWorld
image.png
cd HelloWorld/
python manage.py runserver 0.0.0.0:8002

報錯:

File "manage.py", line 14
) from exc

注意這里:

明確當時安裝django使用的是pip install django還是pip3 install django
如果是后者,應該使用python3 manage.py startapp app來新建app即可解決報錯

python3 manage.py runserver 0.0.0.0:8002

Performing system checks...
System check identified no issues (0 silenced).
You have 14 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, sessions. Run 'python manage.py migrate' to apply them.
July 05, 2018 - 09:56:05
Django version 2.0.7, using settings 'HelloWorld.settings'
Starting development server at http://0.0.0.0:8002/
Quit the server with CONTROL-C.
[05/Jul/2018 09:56:20] "GET / HTTP/1.1" 200 16348
[05/Jul/2018 09:56:20] "GET /static/admin/css/fonts.css HTTP/1.1" 200 423
[05/Jul/2018 09:56:20] "GET /static/admin/fonts/Roboto-Light-webfont.woff HTTP/1.1" 200 81348
[05/Jul/2018 09:56:20] "GET /static/admin/fonts/Roboto-Regular-webfont.woff HTTP/1.1" 200 80304
[05/Jul/2018 09:56:20] "GET /static/admin/fonts/Roboto-Bold-webfont.woff HTTP/1.1" 200 82564
Not Found: /favicon.ico
[05/Jul/2018 09:56:20] "GET /favicon.ico HTTP/1.1" 404 1976

參考資料:https://blog.csdn.net/LZUwujiajun/article/details/80780978

image.png

成功!

  1. 安裝uwsgi 2.0
pip3 install uwsgi

Collecting uwsgi
Downloading https://files.pythonhosted.org/packages/98/b2/19b34b20662d111f7d2f926cdf10e13381761dd7dbd10666b9076cbdcd22/uwsgi-2.0.17.tar.gz (798kB)
100% |████████████████████████████████| 798kB 894kB/s
Installing collected packages: uwsgi
Running setup.py install for uwsgi ... done
Successfully installed uwsgi-2.0.17

查看版本

uwsgi --version

2.0.17

測試uwsgi是否能正常使用:

  • 創(chuàng)建test.py文件
def application(env, start_response):
    start_response('200 OK', [('Content-Type','text/html')])
    return "Hello uwsgi"
  • 執(zhí)行test.py
cd /Users/myweb/test
uwsgi --http :8001 --wsgi-file test.py

報錯:

*** Starting uWSGI 2.0.17 (64bit) on [Thu Jul 5 17:11:16 2018] ***
compiled with version: 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.1) on 05 July 2018 08:25:16
os: Darwin-17.6.0 Darwin Kernel Version 17.6.0: Tue May 8 15:22:16 PDT 2018; root:xnu-4570.61.1~1/RELEASE_X86_64
nodename: ypnmac02deMac-mini.local
machine: x86_64
clock source: unix
detected number of CPU cores: 4
current working directory: /Users/ypn-mac-02/AllMe/test
detected binary path: /Library/Frameworks/Python.framework/Versions/3.7/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
*** WARNING: you are running uWSGI without its master process manager ***
your processes number limit is 709
your memory page size is 4096 bytes
detected max file descriptor number: 256
lock engine: OSX spinlocks
thunder lock: disabled (you can enable it with --thunder-lock)
uWSGI http bound on :8001 fd 4
spawned uWSGI http 1 (pid: 26053)
uwsgi socket 0 bound to TCP address 127.0.0.1:57049 (port auto-assigned) fd 3
Python version: 3.7.0 (v3.7.0:1bf9cc5093, Jun 26 2018, 23:26:24) [Clang 6.0 (clang-600.0.57)]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x7fb87b601d00
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 72888 bytes (71 KB) for 1 cores
*** Operational MODE: single process ***
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x7fb87b601d00 pid: 26052 (default app)
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI worker 1 (and the only) (pid: 26052, cores: 1)
[pid: 26052|app: 0|req: 1/1] 127.0.0.1 () {38 vars in 674 bytes} [Thu Jul 5 17:11:26 2018] GET / => generated 0 bytes in 18 msecs (HTTP/1.1 200) 1 headers in 44 bytes (11 switches on core 0)
[pid: 26052|app: 0|req: 2/2] 127.0.0.1 () {38 vars in 653 bytes} [Thu Jul 5 17:11:27 2018] GET /favicon.ico => generated 0 bytes in 0 msecs (HTTP/1.1 200) 1 headers in 44 bytes (11 switches on core 0)

解決方法:

參考資料:https://segmentfault.com/q/1010000002802250
執(zhí)行

pip3 uninstall uwsgi
yum install zlib-devel bzip2-devel pcre-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel

但是mac沒有yum工具,用pip查找相關的安裝包

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容