我無法使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,但它沒有解決問題。有什麼建議麼?
您確定標記庫位於您虛擬環境的'site-packages'目錄中嗎?取決於你如何設置你的環境,一些庫從src安裝,而不是在站點包文件夾 –