Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 配置不当:导入中间件时出错-Django wsgi错误Apache_Python_Linux_Django_Apache - Fatal编程技术网

Python 配置不当:导入中间件时出错-Django wsgi错误Apache

Python 配置不当:导入中间件时出错-Django wsgi错误Apache,python,linux,django,apache,Python,Linux,Django,Apache,我的AWS Linux服务器中有一个Python Django站点。首先,让我告诉你我在服务器上托管了Django应用程序。默认情况下,服务器已安装Python2.6.9。对于我的应用程序,我在不同的位置(/opt/python2.7.6)编译并安装了Python 2.7.6。不过,默认的python是2.6.9。我的应用程序在一个虚拟环境下,这个虚拟环境是根据这个新安装的Python(2.7.6)创建的。我的Web服务器是Apache2(版本2.4),通过使用下面的命令对Python2.7.6

我的AWS Linux服务器中有一个Python Django站点。首先,让我告诉你我在服务器上托管了Django应用程序。默认情况下,服务器已安装Python2.6.9。对于我的应用程序,我在不同的位置(/opt/python2.7.6)编译并安装了Python 2.7.6。不过,默认的python是2.6.9。我的应用程序在一个虚拟环境下,这个虚拟环境是根据这个新安装的Python(2.7.6)创建的。我的Web服务器是Apache2(版本2.4),通过使用下面的命令对Python2.7.6进行编译,安装了WSGI模块

./configure--with python=/opt/python2.7.6/bin/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"
我已经尝试了很多方法来解决这个问题,但是还没有成功

下面是我的apacheconf文件

<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>

服务器名www.example.com
DocumentRoot/home/testuser/example.com
日志级别信息
ErrorLog/home/testuser/http_error.log
CustomLog/home/testuser/http_access.log组合
WSGIDaemonProcess www.example.com processs=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
别名/media/home/testuser/site\u资产/media
别名/static/home/testuser/example.com/.static\u
命令允许,拒绝
通融
请注意,该站点使用独立的python runserver命令运行良好。

如果您需要任何其他详细信息,请告诉我


谢谢,

我已经解决了。我的服务器上运行了三个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>
WSGIPythonHome/home/testuser/venv
服务器名www.example.com
DocumentRoot/home/testuser/example.com
日志级别信息
ErrorLog/home/testuser/http_error.log
CustomLog/home/testuser/http_access.log组合
WSGIDaemonProcess www.example.com processs=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
别名/media/home/testuser/site\u资产/media
别名/static/home/testuser/example.com/.static\u
命令允许,拒绝
通融
相关:和