Django与mod_wsgi:导入sqlite3时出错

时间:2016-10-11 18:56:19

标签: python django sqlite mod-wsgi

我使用python 3.4,django 1.10.2和virtualenv在FreeBSD上创建了一个非常简单的django项目。我不能让mod_wsgi为我的生活工作,除了构建项目和运行manage.py migrate之外,我几乎没有做任何事情。它似乎在导入sqlite3时遇到问题,但在virtualenv中我可以运行python并导入sqlite3和_sqlite3。

我得到以下内容:

mod_wsgi (pid=15765): Target WSGI script '/server/apache/partner/partner/wsgi.py' cannot be loaded as Python module.
 mod_wsgi (pid=15765): Exception occurred processing WSGI script '/server/apache/partner/partner/wsgi.py'.
 Traceback (most recent call last):
 File "/server/apache/partner/partner/wsgi.py", line 20, in <module>
     application = get_wsgi_application()
 File "/server/apache/partner-env/lib/python3.4/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
     django.setup(set_prefix=False)
 File "/server/apache/partner-env/lib/python3.4/site-packages/django/__init__.py", line 27, in setup
     apps.populate(settings.INSTALLED_APPS)
 File "/server/apache/partner-env/lib/python3.4/site-packages/django/apps/registry.py", line 108, in populate
     app_config.import_models(all_models)
 File "/server/apache/partner-env/lib/python3.4/site-packages/django/apps/config.py", line 199, in import_models
     self.models_module = import_module(models_module_name)
 File "/usr/local/lib/python2.7/importlib/__init__.py", line 37, in import_module
     __import__(name)
 File "/server/apache/partner-env/lib/python3.4/site-packages/django/contrib/auth/models.py", line 4, in <module>
     from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
 File "/server/apache/partner-env/lib/python3.4/site-packages/django/contrib/auth/base_user.py", line 52, in <module>
     class AbstractBaseUser(models.Model):
 File "/server/apache/partner-env/lib/python3.4/site-packages/django/db/models/base.py", line 119, in __new__
     new_class.add_to_class('_meta', Options(meta, app_label))
 File "/server/apache/partner-env/lib/python3.4/site-packages/django/db/models/base.py", line 316, in add_to_class
     value.contribute_to_class(cls, name)
 File "/server/apache/partner-env/lib/python3.4/site-packages/django/db/models/options.py", line 214, in contribute_to_class
     self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
 File "/server/apache/partner-env/lib/python3.4/site-packages/django/db/__init__.py", line 33, in __getattr__
     return getattr(connections[DEFAULT_DB_ALIAS], item)
 File "/server/apache/partner-env/lib/python3.4/site-packages/django/db/utils.py", line 211, in __getitem__
     backend = load_backend(db['ENGINE'])
 File "/server/apache/partner-env/lib/python3.4/site-packages/django/db/utils.py", line 115, in load_backend
     return import_module('%s.base' % backend_name)
 File "/usr/local/lib/python2.7/importlib/__init__.py", line 37, in import_module
     __import__(name)
 File "/server/apache/partner-env/lib/python3.4/site-packages/django/db/backends/sqlite3/base.py", line 39, in <module>
     raise ImproperlyConfigured("Error loading either pysqlite2 or sqlite3 modules (tried in that order): %s" % exc)
 ImproperlyConfigured: Error loading either pysqlite2 or sqlite3 modules (tried in that order): No module named _sqlite3

wsgi.py:

import os
from sys import path
from django.core.wsgi import get_wsgi_application

add_path = '/server/apache/partner'
if add_path not in path:
    path.append(add_path)

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "partner.settings")

application = get_wsgi_application()

-gns

1 个答案:

答案 0 :(得分:0)

感谢@Graham Dumpleton在评论中帮助我。我安装了python 2.7时编译了mod_wsgi,我认为virtualenv足以用于python 3.4,但我需要删除python 2并重新编译mod_wsgi。

-gns