1、废话
之前利用Django写了些测试工具,一直是直接 python manage.py runserver 8081这么来用的。用户量不大,倒也不影响什么。uWSGI+Nginx的性能肯定要好,so 研究了一下
2、环境:
Python: 3.6.3
Django: 1.8
OS: CentOS 6.9 x86_64
uwsgi: 2.0.17
3、安装Python3.6
- 不要删除自带的python2.7,否则会出问题,因为centos许多软件需要依赖系统自带python
- 安装依赖工具 yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel
- 下载 wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz
- 解压 tar -zxvf Python-3.6.3.tgz
- 移动至规范的放软件的目录下 mv Python-3.6.3 /usr/local
- 安装:
- cd /usr/local/Python-3.6.3/
- ./configure
- make&&make install
解决Python.h No such file or directory 1.可以先查看一下含python-devel的包 yum search python | grep python-devel 2.64位安装python-devel.x86_64,32位安装python-devel.i686,我这里安装: sudo yum install python-devel.x86_64 3. 进入/usr/include/python2.7看一下现在有没有Python.h,版本不同目录名不同,我这里是2.7版本。其实也可以看到很多.h文件,python需要库或头文件都在这个地方。
- 更新python的软连接:
rm -rf /usr/bin/python3
ln -s /usr/local/bin/python3.6 /usr/bin/python3
- 验证
python3 -V
4、安装uWSGI
- 安装 pip3 install uwsgi
- 报这个错已经在前面的步骤解决
-
plugins/python/uwsgi_python.h:2:20: fatal error: Python.h: No such file or directory #include <Python.h> ^ compilation terminated. In file included from plugins/python/pyutils.c:1:0: plugins/python/uwsgi_python.h:2:20: fatal error: Python.h: No such file or directory #include <Python.h> ^ compilation terminated.
- 验证
-
def application(env, start_response): start_response('200 OK', [('Content-Type','text/html')]) return [b"Hello Django"]
uwsgi --http :8001 --wsgi-file test.py
浏览器访问,网页能显示 Hello Django 那么就没问题