我无法使Apache / WSGI使用我的VirtualEnv。 我已经添加了以下两行(服务器上的path指向目标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?
UPDATE
我已经更新了以下Ken的build议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是在根和Apache没有权限? 我认为该文件夹根:www – 数据,但它没有解决问题。 有什么build议么?
在我的app.wsgi文件中,我有这样的东西。 您需要将其更改为虚拟环境所在的位置,在本示例中,该位置位于/ opt / ve / ve_name /下。
import os # activate virtualenv activate_this = os.path.expanduser("/opt/ve/ve_name/bin/activate_this.py") execfile(activate_this, dict(__file__=activate_this))