【发布时间】:2011-10-07 02:23:47
【问题描述】:
我无法让 Apache/WSGI 使用我的 VirtualEnv。我已将以下两行(服务器上的路径指向目标 virtualenv 中站点包的实际位置)添加到我的 WSGI 文件中:
import site
site.addsitedir('/sites/mysite/virtpy/lib/python2.6/site-packages')
(来自http://www.foxhop.net/django-virtualenv-apache-mod_wsgi)。但是,当我尝试在浏览器中加载 url 时,我得到 500。检查 apache 日志:
[Sun Jul 17 11:07:11 2011] [error] [client 94.170.105.142] app = import_module(appname)
[Sun Jul 17 11:07:11 2011] [error] [client 94.170.105.142] File "/usr/local/lib/python2.6/dist-packages/django/utils/importlib.py", line 35, in import_module
[Sun Jul 17 11:07:11 2011] [error] [client 94.170.105.142] __import__(name)
[Sun Jul 17 11:07:11 2011] [error] [client 94.170.105.142] TemplateSyntaxError: Caught ImportError while rendering: No module named tagging
[Sun Jul 17 11:07:11 2011] [debug] mod_deflate.c(615): [client 94.170.105.142] Zlib: Compressed 629 to 387 : URL /
所以我猜 VirtualEnv 没有被加载。有人知道如何告诉 Apache / WSGI 使用正确的 virtualenv 吗?
更新
我按照 Ken 的建议更新了 django.wsgi,但现在我在 apache 日志中收到以下错误
[Sun Jul 17 16:46:36 2011] [info] [client 94.170.105.142] mod_wsgi (pid=11260, process='', application='igniteflow-django.com:8090|'): Loading WSGI script '/sites/igniteflow/apache/django.wsgi'.
[Sun Jul 17 16:46:36 2011] [error] [client 94.170.105.142] mod_wsgi (pid=11260): Target WSGI script '/sites/igniteflow/apache/django.wsgi' cannot be loaded as Python module.
[Sun Jul 17 16:46:36 2011] [error] [client 94.170.105.142] mod_wsgi (pid=11260): Exception occurred processing WSGI script '/sites/igniteflow/apache/django.wsgi'.
[Sun Jul 17 16:46:36 2011] [error] [client 94.170.106.142] Traceback (most recent call last):
[Sun Jul 17 16:46:36 2011] [error] [client 94.170.105.142] File "/sites/igniteflow/apache/django.wsgi", line 5, in <module>
[Sun Jul 17 16:46:36 2011] [error] [client 94.170.105.142] execfile(activate_this, dict(__file__=activate_this))
[Sun Jul 17 16:46:36 2011] [error] [client 94.170.105.142] IOError: [Errno 13] Permission denied: '/root/.virtualenvs/igniteflow/bin/activate_this.py'
我认为这是因为 virtualenv 在 root 中并且 apache 没有权限?我将文件夹更改为 root:www-data 但它没有解决问题。有什么建议吗?
【问题讨论】:
-
您确定标记库在您的虚拟环境的
site-packages目录中吗?根据您设置环境的方式,一些库是从 src 安装的,而不是在 site-packages 文件夹中
标签: django apache virtualenv wsgi