我正在使用Apache,mod_wsgi,Virtualenv和Postgres在Ubuntu服务器(v14.04)中配置Django 1.7项目。在所有配置之后,我有一个内部错误,使用此日志:
django.core.exceptions.ImproperlyConfigured:加载psycopg2时出错 模块: /home/ubuntu/VirtualEnvs/env1/lib/python2.7/site-packages/psycopg2/_psycopg.so: 未定义的符号:_Py_ZeroStruct
回溯日志错误:
mod_wsgi (pid=13365): Target WSGI script '/var/www/html/domain.com/projectname/wsgi.py' cannot be loaded as Python module.
mod_wsgi (pid=13365): Exception occurred processing WSGI script '/var/www/html/domain.com/projectname/wsgi.py'.
Traceback (most recent call last):
File "/home/ubuntu/VirtualEnvs/env1/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 23, in <module>
import psycopg2 as Database
File "/home/ubuntu/VirtualEnvs/env1/lib/python2.7/site-packages/psycopg2/__init__.py", line 50, in <module>
from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: /home/ubuntu/VirtualEnvs/env1/lib/python2.7/site-packages/psycopg2/_psycopg.so: undefined symbol: _Py_ZeroStruct
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/var/www/html/domain.com/projectname/wsgi.py", line 16, in <module>
application = get_wsgi_application()
File "/home/ubuntu/VirtualEnvs/env1/lib/python2.7/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
django.setup()
File "/home/ubuntu/VirtualEnvs/env1/lib/python2.7/site-packages/django/__init__.py", line 21, in setup
apps.populate(settings.INSTALLED_APPS)
File "/home/ubuntu/VirtualEnvs/env1/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
app_config.import_models(all_models)
File "/home/ubuntu/VirtualEnvs/env1/lib/python2.7/site-packages/django/apps/config.py", line 202, in import_models
self.models_module = import_module(models_module_name)
File "/usr/lib/python3.4/importlib/__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2231, in _gcd_import
File "<frozen importlib._bootstrap>", line 2214, in _find_and_load
File "<frozen importlib._bootstrap>", line 2203, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1448, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "/home/ubuntu/VirtualEnvs/env1/lib/python2.7/site-packages/django/contrib/auth/models.py", line 40, in <module>
class Permission(models.Model):
File "/home/ubuntu/VirtualEnvs/env1/lib/python2.7/site-packages/django/db/models/base.py", line 122, in __new__
new_class.add_to_class('_meta', Options(meta, **kwargs))
File "/home/ubuntu/VirtualEnvs/env1/lib/python2.7/site-packages/django/db/models/base.py", line 297, in add_to_class
value.contribute_to_class(cls, name)
File "/home/ubuntu/VirtualEnvs/env1/lib/python2.7/site-packages/django/db/models/options.py", line 166, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/home/ubuntu/VirtualEnvs/env1/lib/python2.7/site-packages/django/db/__init__.py", line 40, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/home/ubuntu/VirtualEnvs/env1/lib/python2.7/site-packages/django/db/utils.py", line 242, in __getitem__
backend = load_backend(db['ENGINE'])
File "/home/ubuntu/VirtualEnvs/env1/lib/python2.7/site-packages/django/db/utils.py", line 108, in load_backend
return import_module('%s.base' % backend_name)
File "/usr/lib/python3.4/importlib/__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2231, in _gcd_import
File "<frozen importlib._bootstrap>", line 2214, in _find_and_load
File "<frozen importlib._bootstrap>", line 2203, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1448, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "/home/ubuntu/VirtualEnvs/env1/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 27, in <module>
raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: /home/ubuntu/VirtualEnvs/env1/lib/python2.7/site-packages/psycopg2/_psycopg.so: undefined symbol: _Py_ZeroStruct
Apache .conf文件:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName domain.com
ServerAlias www.domain.com
DocumentRoot /var/www/html/domain.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
WSGIScriptAlias / /var/www/html/domain.com/projectname/wsgi.py
WSGIPythonPath /var/www/html/domain.com:/home/ubuntu/VirtualEnvs/env1/lib/python2.7/site-packages
<Directory /var/www/html/domain.com/projectname>
<Files wsgi.py>
Order deny,allow
Require all granted
</Files>
</Directory>
Alias /media/ /var/www/html/domain.com/media/
Alias /static/ /var/www/html/domain.com/static/
<Directory /var/www/html/domain.com/static>
Require all granted
</Directory>
<Directory /var/www/html/domain.com/media>
Require all granted
</Directory>
项目wsgi文件(/var/www/html/domain.com/projectname/wsgi.py):
import os, sys
sys.path.append('/var/www/html/domain.com')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "projectname.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
psycopg2模块已成功安装,可以正常访问:
python
import psycopg2
知道这里可能会发生什么吗?
谢谢。