2016-12-06 70 views
1

Apache的錯誤504頁Django的Apache和VIRTUALENV導入錯誤:沒有模塊命名的網站

[info] mod_wsgi (pid=): Python home /var/venv/mybox. 
[info] mod_wsgi (pid=): Initializing Python. 
ImportError: No module named site 

後,這是一個幾乎沒有配置的應用程序。

<IfModule mod_wsgi.c> 
WSGIDaemonProcess myapp python-home=/var/venv/mybox 
WSGIProcessGroup myapp 
WSGIScriptAlias//var/www/html/web/myapp/wsgi.py 
WSGISocketPrefix /var/run/wsgi 

<Directory /var/www/html/web> 
<Files wsgi.py> 
Order deny,allow 
Allow from all 
</Files> 
</Directory> 
</IfModule> 

按照每篇文章和教程,我可以。我在CENTOS6上。利用當前虛擬ENV Python 2.7版的默認系統ENV是2.6

$ ldd /etc/httpd/modules/mod_wsgi.so 
    linux-vdso.so.1 => (0x00007ffc06174000) 

mywsgi.py

import os,sys  
from django.core.wsgi import get_wsgi_application  
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myapp.settings") 
sys.path.insert(0,'/var/www/html/web') 
activate_this = '/var/venv/mybox/bin/activate_this.py' 
execfile(activate_this, dict(__file__=activate_this)) 
application = get_wsgi_application() 

PYHTONHOME未設置

回答

3

使用虛擬環境與mod_wsgi的文檔可以在這裏找到:

你的情況最重要的是部分:

在該部分中指出:

When using a Python virtual environment with mod_wsgi, it is very important that it has been created using the same Python installation that mod_wsgi was originally compiled for. It is not possible to use a Python virtual environment to force mod_wsgi to use a different Python version, or even a different Python installation.

You cannot for example force mod_wsgi to use a Python virtual environment created using Python 3.5 when mod_wsgi was originally compiled for Python 2.7. This is because the Python library for the Python installation it was originally compiled against is linked directly into the mod_wsgi module.

所以最有可能發生的事情是mod_wsgi是爲Python 2.6編譯的。在這種情況下,你不能強迫它使用從Python 2.7創建的Python虛擬環境。當你這樣做時,你會看到你看到的有關site模塊丟失的錯誤。

您將需要從系統軟件包中卸載該mod_wsgi,並從源代碼中安裝mod_wsgi,並對Python 2.7進行編譯。要做到這一點,最簡單的方法可能是使用pip install方法中說明:

運行pip install安裝在你的虛擬環境中,然後按照部分說明「連接到Apache安裝'關於配置Apache使用它。

+0

不能/var/venv/mybox/lib/python2.7/site-packages/mod_wsgi/server/mod_wsgi-py27.so加載到服務器:無法打開共享對象文件: 沒有權限。我試圖改變權限 – Jabda

+0

SELinux的配置文件很可能不會允許Apache在該位置使用的東西。嘗試在''/ var/www''下使用虛擬環境。 –

+0

安裝mod_wsgi的使用PIP和移動的virtualenv到/ var/WWW的工作。這是一個內部網站,所以我們可以做出妥協 – Jabda

1

這被認爲是從資本家Documentation 這樣寫: WSGIScriptAlias// path/to/mysite.com/mysite/wsgi.py WSGIPythonPath /path/to/mysite.com

<Directory /path/to/mysite.com/mysite> 
<Files wsgi.py> 
Require all granted 
</Files> 
</Directory> 

,這是專門爲虛擬ENV,你需要的路徑寫入到虛擬的蟒網站packeges ENV

WSGIPythonPath /path/to/mysite.com:/path/to/your/venv/lib/python3.X/site-packages 

問題也可能在 - PYTHONHOME

Change the location of the standard Python libraries. By default, the libraries are searched in prefix/lib/pythonversion and exec_prefix/lib/pythonversion, where prefix and exec_prefix are installation-dependent directories, both defaulting to /usr/local.

When PYTHONHOME is set to a single directory, its value replaces both prefix and exec_prefix. To specify different values for these, set PYTHONHOME to prefix:exec_prefix.

嘗試清理您的PYTHONHOME

user$ export PYTHONHOME= 
+0

我最初遵循的文件,以一個T.然後我試圖格雷厄姆鄧普爾頓博客和教程。我總是得到同樣的錯誤 – Jabda

+0

試圖改變pythonhome位置 –

相關問題