2011-07-17 51 views
3

我无法使Apache/WSGI使用我的VirtualEnv。我加入以下两行(服务器上的路径指向目标的virtualenv站点包的实际位置),以我的WSGI文件:设置Apache和Python WSGI以使用VirtualEnv

import site 
site.addsitedir('/sites/mysite/virtpy/lib/python2.6/site-packages') 

(从http://www.foxhop.net/django-virtualenv-apache-mod_wsgi)。但是,当我尝试加载在浏览器的网址,我得到一个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

我已经更新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没有权限?我把这个文件夹变成root:www-data,但它没有解决问题。有什么建议么?

+0

您确定标记库位于您虚拟环境的'site-packages'目录中吗?取决于你如何设置你的环境,一些库从src安装,而不是在站点包文件夹 –

回答

8

在我的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)) 
+0

IOError:[Errno 13] Permission denied:'/root/.virtualenvs/site1/bin/activate_this.py'你是否知道如何将virtualenv安装在apache可以访问的地方?我试图制作文件夹根目录:www-data但没有更改 – igniteflow

+1

它看起来像你使用的是virtualenvwrapper。要使用virtualenvwrapper更改您的ve的安装位置,您需要更改WORKON_HOME的值; export WORKON_HOME =/opt/Envs;确保该目录存在,并且您需要将当前的envs移到那里,除非您想从头开始创建。在制作过程中,我不打扰使用virtualenvwrapper,我只是使用virtualenv,它允许我把我的ve放在任何我想要的地方,但需要更多的手动工作。 –

+0

谢谢!这让它工作。我将bashrc中的WORKON_HOME设置为/sites/.virtualenv,使用mkvirtualenv --no-site-packages重新创建了virtualenv,现在它已全部运行并正在运行 – igniteflow