2016-03-21 26 views
0

我在我的一個AWS Linux服務器上有一個Python Django站點。首先,讓我告訴你我在服務器上託管我的Django應用程序的過程。默認情況下,服務器已安裝Python 2.6.9。對於我的應用程序,我已經在不同的位置編譯並安裝了Python 2.7.6(/opt/python2.7.6)。不過,默認的python是2.6.9。我的應用程序是在一個虛擬環境下創建的,這個環境是針對這個新安裝的Python(2.7.6)而創建的。我的Web服務器是Apache2(版本2.4),並使用以下命令通過編譯Python 2.7.6來安裝WSGI模塊。錯誤地配置:導入中間件時出錯 - Django wsgi錯誤Apache

的./configure --with-蟒蛇= /選擇/ python2.7.6 /斌/ Python的

我已經相應地配置Apache和我收到以下錯誤。請告訴我如何解決這個問題。

[Mon Mar 21 10:38:32.669216 2016] [:info] [pid 26256] mod_wsgi (pid=26256): Create interpreter 'www.example.com|'. 
[Mon Mar 21 10:38:32.671113 2016] [:info] [pid 26256] mod_wsgi (pid=26256): Adding '/home/testuser/example.com' to path. 
[Mon Mar 21 10:38:32.671607 2016] [:info] [pid 26256] mod_wsgi (pid=26256): Adding '/home/testuser/venv/lib/python2.7/site-packages' to path. 
[Mon Mar 21 10:38:32.672621 2016] [:info] [pid 26256] mod_wsgi (pid=26256): Adding '/home/testuser/example.com/example' to path. 
[Mon Mar 21 10:38:32.681871 2016] [:info] [pid 26256] [client x.x.x.x:46626] mod_wsgi (pid=26256, process='www.example.com', application='www.example.com|'): Loading WSGI script '/home/testuser/example.com/example/wsgi.py'. 
[Mon Mar 21 06:38:33.341024 2016] [:error] [pid 26256] [client x.x.x.x:46626] mod_wsgi (pid=26256): Exception occurred processing WSGI script '/home/testuser/example.com/example/wsgi.py'. 
[Mon Mar 21 06:38:33.341297 2016] [:error] [pid 26256] [client x.x.x.x:46626] Traceback (most recent call last): 
[Mon Mar 21 06:38:33.341478 2016] [:error] [pid 26256] [client x.x.x.x:46626] File "/home/testuser/venv/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 236, in __call__ 
[Mon Mar 21 06:38:33.341772 2016] [:error] [pid 26256] [client x.x.x.x:46626]  self.load_middleware() 
[Mon Mar 21 06:38:33.341926 2016] [:error] [pid 26256] [client x.x.x.x:46626] File "/home/testuser/venv/lib/python2.7/site-packages/django/core/handlers/base.py", line 53, in load_middleware 
[Mon Mar 21 06:38:33.342238 2016] [:error] [pid 26256] [client x.x.x.x:46626]  raise exceptions.ImproperlyConfigured('Error importing middleware %s: "%s"' % (mw_module, e)) 
[Mon Mar 21 06:38:33.342400 2016] [:error] [pid 26256] [client x.x.x.x:46626] ImproperlyConfigured: Error importing middleware django.contrib.auth.middleware: "/home/testuser/venv/lib/python2.7/site-packages/psycopg2/_psycopg.so: undefined symbol: PyUnicodeUCS2_AsUTF8String" 

我已經嘗試了很多事情來解決谷歌建議這個問題,但還沒有工作。

下面是我的apache conf文件。

<VirtualHost *:80> 
ServerName www.example.com 

DocumentRoot /home/testuser/example.com 
LogLevel info 
ErrorLog /home/testuser/http_error.log 
CustomLog /home/testuser/http_access.log combined 

WSGIDaemonProcess www.example.com processes=2 threads=15 display-name=%{GROUP} python-path=/home/testuser/example.com:/home/testuser/venv/lib/python2.7/site-packages 
WSGIProcessGroup www.example.com 

WSGIScriptAlias//home/testuser/example.com/example/wsgi.py 
Alias /media /home/testuser/site_assets/media 
Alias /static /home/testuser/example.com/.static_built 
<Directory /home/testuser/example.com/example> 
    <Files wsgi.py> 
     Order allow,deny 
     Allow from all 
    </Files> 
</Directory> 
</VirtualHost> 

請注意,使用獨立蟒蛇的runserver命令現場工作做好。

請讓我知道你是否需要其他細節。

謝謝,

+0

相關:http://stackoverflow.com/questions/2584198/undefined-symbol-pyunicodeucs2-decode-whilst-trying-to-install-psycopg2和http://stackoverflow.com/questions/25223993/進口錯誤ephem-libastro那麼不確定的符號,pyunicodeucs2-asutf8string – SaeX

回答

0

我已經解決了。我有三個Python版本(2.7.6,2.6.9和2.7.10)在我的服務器上運行,但默認情況下它是2.6.9。即使我的python虛擬環境與2.7.6版本相反,Apache並沒有爲我的應用程序選擇Python。我不知道爲什麼會發生。當我添加** WSGIPythonHome *作爲指向我的虛擬環境python時,在我的apache配置文件的頂部,它工作得很完美。請參閱下面更新的apache配置文件。

WSGIPythonHome /home/testuser/venv 
<VirtualHost *:80> 
ServerName www.example.com 

DocumentRoot /home/testuser/example.com 
LogLevel info 
ErrorLog /home/testuser/http_error.log 
CustomLog /home/testuser/http_access.log combined 

WSGIDaemonProcess www.example.com processes=2 threads=15 display-name=%{GROUP} python-path=/home/testuser/example.com:/home/testuser/venv/lib/python2.7/site-packages 
WSGIProcessGroup www.example.com 

WSGIScriptAlias//home/testuser/example.com/example/wsgi.py 
Alias /media /home/testuser/site_assets/media 
Alias /static /home/testuser/example.com/.static_built 
<Directory /home/testuser/example.com/example> 
    <Files wsgi.py> 
     Order allow,deny 
     Allow from all 
    </Files> 
</Directory> 
</VirtualHost>