python - uWSGI 用于使用 django 运行 Python 2 和 Python3

标签 python django uwsgi

我已经全局安装了 uWSGI,并且它在 Python 3.3 的 virtualenv 和 Django 上运行得很好。但现在我想尝试使用 Python 2.7 运行 uWSGI 的另一个实例。我在Python 2.7的virtualenv中设置了home选项,但它使用的python版本仍然是3.3版本。

目前我对 uWSGI 有这样的设置:

 # Django-related settings
 # the base directory (full path)
 chdir           = /home/srvadmin/webapps2.7/project
 # Django's wsgi file
 module          = project.wsgi
 # the virtualenv (full path)
 home            = /home/srvadmin/py2.7

 # process-related settings
 # master
 master          = true
 # maximum number of worker processes
 processes       = 10
 # the socket (use the full path to be safe
 socket          = /tmp/mysite2.7.sock
 # ... with appropriate permissions - may be needed
 chmod-socket    = 666
 # clear environment on exit
 vacuum          = true

但我总是明白这一点

uWSGI http bound on 0.0.0.0:1234 fd 4
spawned uWSGI http 1 (pid: 31507)
uwsgi socket 0 bound to TCP address 127.0.0.1:33896 (port auto-assigned) fd 3
Python version: 3.3.2 (default, May 16 2013, 18:35:00)  [GCC 4.6.3]
Set PythonHome to /home/srvadmin/py2.7/
Fatal Python error: Py_Initialize: Unable to get the locale encoding
ImportError: No module named 'encodings'
Aborted

最佳答案

您的 uWSGI 二进制文件与特定的 libpython(3.3 版本)链接。您必须为 python2.7 构建 uWSGI 的第二个副本或使用模块化构建:

(来自源目录)

python3 uwsgiconfig.py --build nolang

python3 uwsgiconfig.py --plugin 插件/python nolang python33

python2 uwsgiconfig.py --plugin 插件/python nolang python27

您将以“uwsgi”二进制文件、“python33_plugin.so”和“python27_plugin.so”结束

关于python - uWSGI 用于使用 django 运行 Python 2 和 Python3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18456744/

相关文章:

Python + Scrapy : Issues running "ImagesPipeline" when running crawler from script

django - Celery+Docker+Django -- 让任务工作

python - 无法在 django 中使用多个数据库的查询集

python - 如何在linux终端直接执行*.pyc文件

python - Mac OS X 上的 Pip ImportError : cannot import name walk_packages

python - 在发送实际响应之前发送请求的间歇状态

django - Nginx 连接重置,来自 uWsgi 的响应丢失

python - UWSGI + NGINX 502 错误网关

python - SSLHandshakeError - Google App Engine

python - Django 过滤器根据多个条件在 order_by 之后返回重复项