Django (mod_wsgi) 处理 WSGI 脚本时发生异常
Django (mod_wsgi) Exception occurred processing WSGI script
我是 Apache 和 mod_wsgi 的初学者。不过,我了解 Apache 服务器的基本概念。我需要一位救星,因为我几乎没有人可以寻求帮助。
我的问题如下:
- 我可以 运行
python manage.py runserver 0.0.0.0:8000
并且我的应用程序 运行 在服务器上很好 [=78=]
- 但是,当我使用 Apache 服务器为我的站点提供服务时。事情并不顺利。
返回的两个主要错误是:
ImproperlyConfigured: Error loading psycopg2 module: /opt/payupjack/payupjack-env/lib/python2.7/site-packages/psycopg2/_psycopg.so: wrong ELF class: ELFCLASS32
和
ImproperlyConfigured: Error importing middleware django_openid.consumer: "cannot import name utils"
文件夹结构
payupjack
|-payupjack-env (virtualenv for payupjack)
|- (virtualenv stuffs...)
|- PayupJack (My application)
|- All the code required by this application
我试过的
将 virtualenv 站点包文件夹中的文件夹 django_openid 的用户所有权更改为 'www-data'
已将 'www-data' 用户添加到 'ubuntu' 组(以便 'www-data' 与 'ubuntu' 共享相同的权限)
运行 'wsgi.py' 单独 运行 没问题。
运行 python manage.py runserver
也可以
试图注释掉模块consumer.py
(在django_openid模块中)导入utils
的行,但我仍然得到同样的错误。这真的很奇怪,我不知道如何理解。
遵循了许多关于此问题不同变体的 Whosebug 建议。到目前为止没有任何效果。
额外信息
完整的 Apache 错误日志 returns 以下。
[Tue Nov 10 20:02:12.411960 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:12632] mod_wsgi (pid=20821): Exception occurred processing WSGI script '/opt/payupjack/payupjack-env/PayupJack/wsgi.py'.
[Tue Nov 10 20:02:12.411987 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:12632] Traceback (most recent call last):
[Tue Nov 10 20:02:12.412002 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:12632] File "/opt/payupjack/payupjack-env/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 250, in __call__
[Tue Nov 10 20:02:12.412091 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:12632] self.load_middleware()
[Tue Nov 10 20:02:12.412105 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:12632] File "/opt/payupjack/payupjack-env/lib/python2.7/site-packages/django/core/handlers/base.py", line 45, in load_middleware
[Tue Nov 10 20:02:12.412209 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:12632] mod = import_module(mw_module)
[Tue Nov 10 20:02:12.412224 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:12632] File "/opt/payupjack/payupjack-env/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
[Tue Nov 10 20:02:12.412262 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:12632] __import__(name)
[Tue Nov 10 20:02:12.412272 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:12632] File "/opt/payupjack/payupjack-env/lib/python2.7/site-packages/django_openid/consumer.py", line 14, in <module>
[Tue Nov 10 20:02:12.412390 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:12632] from django.shortcuts import render_to_response
[Tue Nov 10 20:02:12.412403 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:12632] File "/opt/payupjack/payupjack-env/lib/python2.7/site-packages/django/shortcuts/__init__.py", line 10, in <module>
[Tue Nov 10 20:02:12.412467 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:12632] from django.db.models.manager import Manager
[Tue Nov 10 20:02:12.412477 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:12632] File "/opt/payupjack/payupjack-env/lib/python2.7/site-packages/django/db/__init__.py", line 78, in <module>
[Tue Nov 10 20:02:12.412525 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:12632] connection = connections[DEFAULT_DB_ALIAS]
[Tue Nov 10 20:02:12.412535 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:12632] File "/opt/payupjack/payupjack-env/lib/python2.7/site-packages/django/db/utils.py", line 93, in __getitem__
[Tue Nov 10 20:02:12.412595 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:12632] backend = load_backend(db['ENGINE'])
[Tue Nov 10 20:02:12.412615 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:12632] File "/opt/payupjack/payupjack-env/lib/python2.7/site-packages/django/db/utils.py", line 33, in load_backend
[Tue Nov 10 20:02:12.412630 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:12632] return import_module('.base', backend_name)
[Tue Nov 10 20:02:12.412640 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:12632] File "/opt/payupjack/payupjack-env/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
[Tue Nov 10 20:02:12.412652 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:12632] __import__(name)
[Tue Nov 10 20:02:12.412659 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:12632] File "/opt/payupjack/payupjack-env/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 24, in <module>
[Tue Nov 10 20:02:12.412726 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:12632] raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
[Tue Nov 10 20:02:12.412743 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:12632] ImproperlyConfigured: Error loading psycopg2 module: /opt/payupjack/payupjack-env/lib/python2.7/site-packages/psycopg2/_psycopg.so: wrong ELF class: ELFCLASS32
[Tue Nov 10 15:02:13.107340 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] mod_wsgi (pid=20821): Exception occurred processing WSGI script '/opt/payupjack/payupjack-env/PayupJack/wsgi.py'.
[Tue Nov 10 15:02:13.107383 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] Traceback (most recent call last):
[Tue Nov 10 15:02:13.107402 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] File "/opt/payupjack/payupjack-env/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 250, in __call__
[Tue Nov 10 15:02:13.107426 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] self.load_middleware()
[Tue Nov 10 15:02:13.107436 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] File "/opt/payupjack/payupjack-env/lib/python2.7/site-packages/django/core/handlers/base.py", line 47, in load_middleware
[Tue Nov 10 15:02:13.107449 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] raise exceptions.ImproperlyConfigured('Error importing middleware %s: "%s"' % (mw_module, e))
[Tue Nov 10 15:02:13.107467 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] ImproperlyConfigured: Error importing middleware django_openid.consumer: "cannot import name utils"
[Tue Nov 10 15:02:13.407277 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] mod_wsgi (pid=20821): Exception occurred processing WSGI script '/opt/payupjack/payupjack-env/PayupJack/wsgi.py'.
[Tue Nov 10 15:02:13.407306 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] Traceback (most recent call last):
[Tue Nov 10 15:02:13.407322 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] File "/opt/payupjack/payupjack-env/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 250, in __call__
[Tue Nov 10 15:02:13.407343 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] self.load_middleware()
[Tue Nov 10 15:02:13.407352 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] File "/opt/payupjack/payupjack-env/lib/python2.7/site-packages/django/core/handlers/base.py", line 47, in load_middleware
[Tue Nov 10 15:02:13.407364 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] raise exceptions.ImproperlyConfigured('Error importing middleware %s: "%s"' % (mw_module, e))
[Tue Nov 10 15:02:13.407381 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] ImproperlyConfigured: Error importing middleware django_openid.consumer: "cannot import name utils"
[Tue Nov 10 15:02:14.197060 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] mod_wsgi (pid=20821): Exception occurred processing WSGI script '/opt/payupjack/payupjack-env/PayupJack/wsgi.py'.
[Tue Nov 10 15:02:14.197098 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] Traceback (most recent call last):
[Tue Nov 10 15:02:14.197114 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] File "/opt/payupjack/payupjack-env/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 250, in __call__
[Tue Nov 10 15:02:14.197136 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] self.load_middleware()
[Tue Nov 10 15:02:14.197144 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] File "/opt/payupjack/payupjack-env/lib/python2.7/site-packages/django/core/handlers/base.py", line 47, in load_middleware
[Tue Nov 10 15:02:14.197157 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] raise exceptions.ImproperlyConfigured('Error importing middleware %s: "%s"' % (mw_module, e))
[Tue Nov 10 15:02:14.197174 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] ImproperlyConfigured: Error importing middleware django_openid.consumer: "cannot import name utils"
[Tue Nov 10 15:02:14.252928 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] mod_wsgi (pid=20821): Exception occurred processing WSGI script '/opt/payupjack/payupjack-env/PayupJack/wsgi.py'.
[Tue Nov 10 15:02:14.252946 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] Traceback (most recent call last):
[Tue Nov 10 15:02:14.252958 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] File "/opt/payupjack/payupjack-env/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 250, in __call__
[Tue Nov 10 15:02:14.252975 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] self.load_middleware()
[Tue Nov 10 15:02:14.252983 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] File "/opt/payupjack/payupjack-env/lib/python2.7/site-packages/django/core/handlers/base.py", line 47, in load_middleware
[Tue Nov 10 15:02:14.252994 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] raise exceptions.ImproperlyConfigured('Error importing middleware %s: "%s"' % (mw_module, e))
[Tue Nov 10 15:02:14.253006 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] ImproperlyConfigured: Error importing middleware django_openid.consumer: "cannot import name utils"
wsgi.py
给出为:
from django.core.handlers.wsgi import WSGIHandler
import os
import sys
import site
ALLDIRS = ['/opt/payupjack/payupjack-env/PayupJack']
# redirect sys.stdout to sys.stderr for bad libraries like geopy that uses
# print statements for optional import exceptions.
sys.stdout = sys.stderr
prev_sys_path = list(sys.path)
print prev_sys_path
site.addsitedir('/opt/payupjack/payupjack-env/lib/python2.7/site-packages')
sys.path.append('/opt')
sys.path.append('/opt/payupjack')
sys.path.append('/opt/payupjack/payupjack-env')
sys.path.append('/opt/payupjack/payupjack-env/PayupJack')
# Reorder sys.path so new directories at the front.
new_sys_path = []
for item in list(sys.path):
if item not in prev_sys_path:
new_sys_path.append(item)
sys.path.remove(item)
sys.path[:0] = new_sys_path
activate_this = '/opt/payupjack/payupjack-env/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))
from os.path import abspath, dirname, join
print sys.path
os.environ["DJANGO_SETTINGS_MODULE"] = "PayupJack.settings"
sys.path.insert(0, join("/opt/payupjack/payupjack-env/PayupJack", "apps"))
import djcelery
djcelery.setup_loader()
print 'Last step of WSGI'
application = WSGIHandler()
print 'Done final step. '
这是我的 Apache 配置文件:
WSGIPythonPath /opt/payupjack/payupjack_env/lib/python2.7
<VirtualHost *:80>
ServerAdmin webmaster@localhost
WSGIDaemonProcess payupjack python-path=/opt/payupjack/payupjack-env:/opt/payupjack/payupjack-env/lib/python2.7/site-packages processes=1 threads=1
WSGIProcessGroup payupjack
WSGIApplicationGroup %{GLOBAL}
WSGIPassAuthorization On
WSGIScriptAlias / /opt/payupjack/payupjack-env/PayupJack/wsgi.py
Alias /static/ /opt/payupjack/payupjack-env/PayupJack/static
<Directory /opt/payupjack/payupjack-env/PayupJack>
Order deny,allow
#Allow from all
Require all granted
</Directory>
ErrorLog /opt/payupjack/payupjack-env/logs/error.log
CustomLog /opt/payupjack/payupjack-env/logs/access.log combined
</VirtualHost>
新信息
mod_wsgi.so
returnsldd
:
linux-vdso.so.1 => (0x00007fff815f2000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007ff5b3fec000)
libpython2.7.so.1.0 => /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 (0x00007ff5b3a88000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ff5b36c2000)
/lib64/ld-linux-x86-64.so.2 (0x00007ff5b443c000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007ff5b34a9000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007ff5b32a5000)
libutil.so.1 => /lib/x86_64-linux-gnu/libutil.so.1 (0x00007ff5b30a1000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007ff5b2d9b000)
我也在我的整个硬盘上快速找到了一个 python 库与上面的相匹配,它位于:
/usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0
问题是由于路径问题(感谢 Graham 指出如何检查 psycopg2.so
的位数和位置)。我的应用程序使用 VirtualEnv。由于某些原因,我第一次没有正确设置 VirtualEnv。因此,所有通过 pip
安装的包都保留在 OS 的 python 路径中,而不是 VirtualEnv。
解决方案是删除安装在 OS 的 Python 路径上的所有软件包。然后,重新创建一个新的 VirtualEnv 并执行典型的 pip install
。确保所有包都安装在 VirtualEnv 路径中。一旦我这样做了,一切都很顺利。
我是 Apache 和 mod_wsgi 的初学者。不过,我了解 Apache 服务器的基本概念。我需要一位救星,因为我几乎没有人可以寻求帮助。
我的问题如下:
- 我可以 运行
python manage.py runserver 0.0.0.0:8000
并且我的应用程序 运行 在服务器上很好 [=78=] - 但是,当我使用 Apache 服务器为我的站点提供服务时。事情并不顺利。
返回的两个主要错误是:
ImproperlyConfigured: Error loading psycopg2 module: /opt/payupjack/payupjack-env/lib/python2.7/site-packages/psycopg2/_psycopg.so: wrong ELF class: ELFCLASS32
和
ImproperlyConfigured: Error importing middleware django_openid.consumer: "cannot import name utils"
文件夹结构
payupjack
|-payupjack-env (virtualenv for payupjack)
|- (virtualenv stuffs...)
|- PayupJack (My application)
|- All the code required by this application
我试过的
将 virtualenv 站点包文件夹中的文件夹 django_openid 的用户所有权更改为 'www-data'
已将 'www-data' 用户添加到 'ubuntu' 组(以便 'www-data' 与 'ubuntu' 共享相同的权限)
运行 'wsgi.py' 单独 运行 没问题。
运行
python manage.py runserver
也可以试图注释掉模块
consumer.py
(在django_openid模块中)导入utils
的行,但我仍然得到同样的错误。这真的很奇怪,我不知道如何理解。遵循了许多关于此问题不同变体的 Whosebug 建议。到目前为止没有任何效果。
额外信息
完整的 Apache 错误日志 returns 以下。
[Tue Nov 10 20:02:12.411960 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:12632] mod_wsgi (pid=20821): Exception occurred processing WSGI script '/opt/payupjack/payupjack-env/PayupJack/wsgi.py'.
[Tue Nov 10 20:02:12.411987 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:12632] Traceback (most recent call last):
[Tue Nov 10 20:02:12.412002 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:12632] File "/opt/payupjack/payupjack-env/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 250, in __call__
[Tue Nov 10 20:02:12.412091 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:12632] self.load_middleware()
[Tue Nov 10 20:02:12.412105 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:12632] File "/opt/payupjack/payupjack-env/lib/python2.7/site-packages/django/core/handlers/base.py", line 45, in load_middleware
[Tue Nov 10 20:02:12.412209 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:12632] mod = import_module(mw_module)
[Tue Nov 10 20:02:12.412224 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:12632] File "/opt/payupjack/payupjack-env/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
[Tue Nov 10 20:02:12.412262 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:12632] __import__(name)
[Tue Nov 10 20:02:12.412272 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:12632] File "/opt/payupjack/payupjack-env/lib/python2.7/site-packages/django_openid/consumer.py", line 14, in <module>
[Tue Nov 10 20:02:12.412390 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:12632] from django.shortcuts import render_to_response
[Tue Nov 10 20:02:12.412403 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:12632] File "/opt/payupjack/payupjack-env/lib/python2.7/site-packages/django/shortcuts/__init__.py", line 10, in <module>
[Tue Nov 10 20:02:12.412467 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:12632] from django.db.models.manager import Manager
[Tue Nov 10 20:02:12.412477 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:12632] File "/opt/payupjack/payupjack-env/lib/python2.7/site-packages/django/db/__init__.py", line 78, in <module>
[Tue Nov 10 20:02:12.412525 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:12632] connection = connections[DEFAULT_DB_ALIAS]
[Tue Nov 10 20:02:12.412535 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:12632] File "/opt/payupjack/payupjack-env/lib/python2.7/site-packages/django/db/utils.py", line 93, in __getitem__
[Tue Nov 10 20:02:12.412595 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:12632] backend = load_backend(db['ENGINE'])
[Tue Nov 10 20:02:12.412615 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:12632] File "/opt/payupjack/payupjack-env/lib/python2.7/site-packages/django/db/utils.py", line 33, in load_backend
[Tue Nov 10 20:02:12.412630 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:12632] return import_module('.base', backend_name)
[Tue Nov 10 20:02:12.412640 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:12632] File "/opt/payupjack/payupjack-env/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
[Tue Nov 10 20:02:12.412652 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:12632] __import__(name)
[Tue Nov 10 20:02:12.412659 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:12632] File "/opt/payupjack/payupjack-env/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 24, in <module>
[Tue Nov 10 20:02:12.412726 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:12632] raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
[Tue Nov 10 20:02:12.412743 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:12632] ImproperlyConfigured: Error loading psycopg2 module: /opt/payupjack/payupjack-env/lib/python2.7/site-packages/psycopg2/_psycopg.so: wrong ELF class: ELFCLASS32
[Tue Nov 10 15:02:13.107340 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] mod_wsgi (pid=20821): Exception occurred processing WSGI script '/opt/payupjack/payupjack-env/PayupJack/wsgi.py'.
[Tue Nov 10 15:02:13.107383 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] Traceback (most recent call last):
[Tue Nov 10 15:02:13.107402 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] File "/opt/payupjack/payupjack-env/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 250, in __call__
[Tue Nov 10 15:02:13.107426 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] self.load_middleware()
[Tue Nov 10 15:02:13.107436 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] File "/opt/payupjack/payupjack-env/lib/python2.7/site-packages/django/core/handlers/base.py", line 47, in load_middleware
[Tue Nov 10 15:02:13.107449 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] raise exceptions.ImproperlyConfigured('Error importing middleware %s: "%s"' % (mw_module, e))
[Tue Nov 10 15:02:13.107467 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] ImproperlyConfigured: Error importing middleware django_openid.consumer: "cannot import name utils"
[Tue Nov 10 15:02:13.407277 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] mod_wsgi (pid=20821): Exception occurred processing WSGI script '/opt/payupjack/payupjack-env/PayupJack/wsgi.py'.
[Tue Nov 10 15:02:13.407306 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] Traceback (most recent call last):
[Tue Nov 10 15:02:13.407322 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] File "/opt/payupjack/payupjack-env/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 250, in __call__
[Tue Nov 10 15:02:13.407343 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] self.load_middleware()
[Tue Nov 10 15:02:13.407352 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] File "/opt/payupjack/payupjack-env/lib/python2.7/site-packages/django/core/handlers/base.py", line 47, in load_middleware
[Tue Nov 10 15:02:13.407364 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] raise exceptions.ImproperlyConfigured('Error importing middleware %s: "%s"' % (mw_module, e))
[Tue Nov 10 15:02:13.407381 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] ImproperlyConfigured: Error importing middleware django_openid.consumer: "cannot import name utils"
[Tue Nov 10 15:02:14.197060 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] mod_wsgi (pid=20821): Exception occurred processing WSGI script '/opt/payupjack/payupjack-env/PayupJack/wsgi.py'.
[Tue Nov 10 15:02:14.197098 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] Traceback (most recent call last):
[Tue Nov 10 15:02:14.197114 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] File "/opt/payupjack/payupjack-env/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 250, in __call__
[Tue Nov 10 15:02:14.197136 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] self.load_middleware()
[Tue Nov 10 15:02:14.197144 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] File "/opt/payupjack/payupjack-env/lib/python2.7/site-packages/django/core/handlers/base.py", line 47, in load_middleware
[Tue Nov 10 15:02:14.197157 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] raise exceptions.ImproperlyConfigured('Error importing middleware %s: "%s"' % (mw_module, e))
[Tue Nov 10 15:02:14.197174 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] ImproperlyConfigured: Error importing middleware django_openid.consumer: "cannot import name utils"
[Tue Nov 10 15:02:14.252928 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] mod_wsgi (pid=20821): Exception occurred processing WSGI script '/opt/payupjack/payupjack-env/PayupJack/wsgi.py'.
[Tue Nov 10 15:02:14.252946 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] Traceback (most recent call last):
[Tue Nov 10 15:02:14.252958 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] File "/opt/payupjack/payupjack-env/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 250, in __call__
[Tue Nov 10 15:02:14.252975 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] self.load_middleware()
[Tue Nov 10 15:02:14.252983 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] File "/opt/payupjack/payupjack-env/lib/python2.7/site-packages/django/core/handlers/base.py", line 47, in load_middleware
[Tue Nov 10 15:02:14.252994 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] raise exceptions.ImproperlyConfigured('Error importing middleware %s: "%s"' % (mw_module, e))
[Tue Nov 10 15:02:14.253006 2015] [:error] [pid 20821:tid 139665119233792] [remote 192.0.163.234:7512] ImproperlyConfigured: Error importing middleware django_openid.consumer: "cannot import name utils"
wsgi.py
给出为:
from django.core.handlers.wsgi import WSGIHandler
import os
import sys
import site
ALLDIRS = ['/opt/payupjack/payupjack-env/PayupJack']
# redirect sys.stdout to sys.stderr for bad libraries like geopy that uses
# print statements for optional import exceptions.
sys.stdout = sys.stderr
prev_sys_path = list(sys.path)
print prev_sys_path
site.addsitedir('/opt/payupjack/payupjack-env/lib/python2.7/site-packages')
sys.path.append('/opt')
sys.path.append('/opt/payupjack')
sys.path.append('/opt/payupjack/payupjack-env')
sys.path.append('/opt/payupjack/payupjack-env/PayupJack')
# Reorder sys.path so new directories at the front.
new_sys_path = []
for item in list(sys.path):
if item not in prev_sys_path:
new_sys_path.append(item)
sys.path.remove(item)
sys.path[:0] = new_sys_path
activate_this = '/opt/payupjack/payupjack-env/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))
from os.path import abspath, dirname, join
print sys.path
os.environ["DJANGO_SETTINGS_MODULE"] = "PayupJack.settings"
sys.path.insert(0, join("/opt/payupjack/payupjack-env/PayupJack", "apps"))
import djcelery
djcelery.setup_loader()
print 'Last step of WSGI'
application = WSGIHandler()
print 'Done final step. '
这是我的 Apache 配置文件:
WSGIPythonPath /opt/payupjack/payupjack_env/lib/python2.7
<VirtualHost *:80>
ServerAdmin webmaster@localhost
WSGIDaemonProcess payupjack python-path=/opt/payupjack/payupjack-env:/opt/payupjack/payupjack-env/lib/python2.7/site-packages processes=1 threads=1
WSGIProcessGroup payupjack
WSGIApplicationGroup %{GLOBAL}
WSGIPassAuthorization On
WSGIScriptAlias / /opt/payupjack/payupjack-env/PayupJack/wsgi.py
Alias /static/ /opt/payupjack/payupjack-env/PayupJack/static
<Directory /opt/payupjack/payupjack-env/PayupJack>
Order deny,allow
#Allow from all
Require all granted
</Directory>
ErrorLog /opt/payupjack/payupjack-env/logs/error.log
CustomLog /opt/payupjack/payupjack-env/logs/access.log combined
</VirtualHost>
新信息
mod_wsgi.so
returnsldd
:
linux-vdso.so.1 => (0x00007fff815f2000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007ff5b3fec000)
libpython2.7.so.1.0 => /usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0 (0x00007ff5b3a88000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007ff5b36c2000)
/lib64/ld-linux-x86-64.so.2 (0x00007ff5b443c000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007ff5b34a9000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007ff5b32a5000)
libutil.so.1 => /lib/x86_64-linux-gnu/libutil.so.1 (0x00007ff5b30a1000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007ff5b2d9b000)
我也在我的整个硬盘上快速找到了一个 python 库与上面的相匹配,它位于:
/usr/lib/x86_64-linux-gnu/libpython2.7.so.1.0
问题是由于路径问题(感谢 Graham 指出如何检查 psycopg2.so
的位数和位置)。我的应用程序使用 VirtualEnv。由于某些原因,我第一次没有正确设置 VirtualEnv。因此,所有通过 pip
安装的包都保留在 OS 的 python 路径中,而不是 VirtualEnv。
解决方案是删除安装在 OS 的 Python 路径上的所有软件包。然后,重新创建一个新的 VirtualEnv 并执行典型的 pip install
。确保所有包都安装在 VirtualEnv 路径中。一旦我这样做了,一切都很顺利。