我想部署Django(位于virtualenv)在Apache上使用WSGI部署。我下面从https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/modwsgi/Django Apache的wsgi virtualenv导入错误
wsgi.py默认教程(着Django生成的默认之一,评论丢弃):
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "server.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
apache2.conf(它只是在Debian中相同的httpd.conf )。这追加到结束:
WSGIScriptAlias//home/user/Desktop/expofit/expofit_hg/py/server/server/wsgi.py
WSGIDaemonProcess example.com python-path=/home/user/Desktop/expofit/expofit_hg/py/server:/home/user/Desktop/expofit/expofit_env/lib/python2.7/site-packages
WSGIProcessGroup example.com
<Directory /home/user/Desktop/expofit/expofit_hg/py/server/server>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
Alias /static/ /home/user/Desktop/expofit/expofit_hg/py/server/server/static
<Directory /home/user/Desktop/expofit/expofit_hg/py/server/server/static>
Order deny,allow
Allow from all
</Directory>
然而,这结束与一个错误:
[Thu Dec 06 17:08:40 2012] [error] [client 192.168.56.1] ImportError: No module named django.core.wsgi
看来,标准的Python是可访问的,因为
import os
产生任何错误。所以看起来从virtualenv导入的模块是不可导入的。 教程说:
A further change required to the above configuration if you use daemon mode is that you can't use WSGIPythonPath; instead you should use the python-path option to WSGIDaemonProcess, for example:
WSGIDaemonProcess example.com python-path=/path/to/mysite.com:/path/to/venv/lib/python2.7/site-packages
WSGIProcessGroup example.com
我缺少什么?
做了什么用途和教程建议。在Apache日志中结束了:“ImportError:No module named site”。将代码更改为之前的版本,但日志不断更新,因此wsgi.py中没有更多的“导入网站” – TheMeaningfulEngineer
然后,您正在使用针对与虚拟环境不同的Python版本编译的mod_wsgi,或者你填满了你设置WSGIPythonHome的东西。因为如果使用mod_wsgi 3.4而不是WGSIPythonHome,则使用守护进程模式,请使用WSGIDaemonProcess指令的python-home选项。 –
@GrahamDumpleton,但我没有看到'WSGIDaemonProcess'指令中的'python-home'选项 https://code.google。com/p/modwsgi/wiki/ConfigurationDirectives#WSGIDaemonProcess – eldos