该错误仅出现在 openSuse Server 12.3 x64(最小安装)中。具有相同 apache 设置的相同代码在 Ubuntu 发行版中就像魅力一样。运行 django 项目时出现几个错误。
错误:访问页面 url 时“500 内部服务器错误”
Traceback (most recent call last):
mod_wsgi (pid=4601): Target WSGI script '/srv/www/compare/htdocs/config/apache/wsgi.py' cannot be loaded as Python module.
mod_wsgi (pid=4601): Exception occurred processing WSGI script '/srv/www/compare/htdocs/config/apache/wsgi.py'.
Traceback (most recent call last):
File "/var/www/thehomeboard/wwwhome/wsgi.py", line 37, in <module>
application = get_wsgi_application()
File "/usr/lib/python2.7/dist-packages/django/core/wsgi.py", line 14, in get_wsgi_application
django.setup()
File "/usr/lib/python2.7/dist-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/lib/python2.7/dist-packages/django/apps/registry.py", line 78, in populate
raise RuntimeError("populate() isn't reentrant")
File "/usr/lib/python2.7/site-packages/django/apps/registry.py", line 78, in populate
raise RuntimeError("populate() isn't reentrant")
RuntimeError: populate() isn't reentrant
错误:运行 python wsgi.py 时。(运行python manage.py时出现同样的错误)
Traceback (most recent call last):
File "/srv/www/compare/htdocs/config/apache/wsgi.py", line 28, in <module>
application = get_wsgi_application()
File "/usr/lib/python2.7/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
django.setup()
File "/usr/lib/python2.7/site-packages/django/__init__.py", line 18, in setup
apps.populate(settings.INSTALLED_APPS)
File "/usr/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
File "/usr/lib/python2.7/site-packages/django/apps/config.py", line 112, in create
mod = import_module(mod_path)
File "/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/usr/lib/python2.7/site-packages/debug_toolbar/apps.py", line 6, in <module>
from debug_toolbar import settings as dt_settings
File "/usr/lib/python2.7/site-packages/debug_toolbar/settings.py", line 8, in <module>
from debug_toolbar.compat import import_module
File "/usr/lib/python2.7/site-packages/debug_toolbar/compat.py", line 39, in <module>
from django.test import ( # NOQA
File "/usr/lib/python2.7/site-packages/django/test/__init__.py", line 5, in <module>
from django.test.client import Client, RequestFactory
File "/usr/lib/python2.7/site-packages/django/test/client.py", line 22, in <module>
from django.test import signals
ImportError: cannot import name signals
项目的配置如下所示:
虚拟主机配置
<VirtualHost *:80>
ServerName compare.django
DocumentRoot /srv/www/compare/htdocs
ErrorLog /srv/www/compare/log/error.log
CustomLog /srv/www/compare/log/custom.log combined
WSGIDaemonProcess compare python-path=/srv/www/compare/htdocs:/usr/lib/python2.7/site-packages processes=2 threads=5
WSGIScriptAlias / /srv/www/compare/htdocs/config/apache/wsgi.py
<Directory /srv/www/compare/htdocs>
<Files wsgi.py>
#Require all granted
Order deny,allow
Allow from all
</Files>
</Directory>
<Directory /srv/www/compare/htdocs/config/apache>
WSGIProcessGroup compare
#Require all granted
Order deny,allow
Allow from all
</Directory>
Alias /static/ /srv/www/compare/htdocs/static/
<Directory /srv/www/compare/htdocs/static>
#Require all granted
Order deny,allow
Allow from all
</Directory>
Alias /storage/ /srv/www/compare/htdocs/storage/
<Directory /srv/www/compare/htdocs/storage>
#Require all granted
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
wsgi.py
import os, sys
from django.core.wsgi import get_wsgi_application
# Calculate the path based on the location of the WSGI script.
apache_configuration = os.path.dirname(__file__)
project = os.path.dirname(apache_configuration)
workspace = os.path.dirname(project)
sys.path.append(workspace)
sys.path.append(project)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
application = get_wsgi_application()
Python环境信息:
mod_wsgi 设置
$ldd /usr/lib64/apache2/mod_wsgi.so
linux-vdso.so.1 (0x00007fff67947000)
libpython2.7.so.1.0 => /usr/lib64/libpython2.7.so.1.0 (0x00007f698c085000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f698be69000)
libc.so.6 => /lib64/libc.so.6 (0x00007f698babb000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f698b8b7000)
libutil.so.1 => /lib64/libutil.so.1 (0x00007f698b6b4000)
libm.so.6 => /lib64/libm.so.6 (0x00007f698b3b5000)
/lib64/ld-linux-x86-64.so.2 (0x00007f698c651000)
python import sys, django
print sys.prefix # '/usr'
print sys.version # '2.7.3 (default, Apr 14 2012, 08:58:41) [GCC]'
print sys.version_info # 'sys.version_info(major=2, minor=7, micro=3, releaselevel='final', serial=0)'
print django.__file__ # '/usr/lib/python2.7/site-packages/django/__init__.pyc'