使用django运行Python 2和Python3的uWSGI

时间:2013-08-27 04:05:22

标签: 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

1 个答案:

答案 0 :(得分:2)

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

(来自源目录)

python3 uwsgiconfig.py --build nolang

python3 uwsgiconfig.py --plugin plugins / python nolang python33

python2 uwsgiconfig.py --plugin plugins / python nolang python27

你将以'uwsgi'二进制文件和'python33_plugin.so'和'python27_plugin.so'结尾