Django with mod_wsgi: error importing sqlite3
<p>I made a very simple project with django using python 3.4, django 1.10.2, and virtualenv all on FreeBSD. I cannot get mod_wsgi to work for the life of me, and I have done almost nothing beyond building the project and running manage.py migrate. It seems to be having a problem importing sqlite3 but in the virtualenv I can run python and import sqlite3 and _sqlite3.</p>

<p>I get the following:</p>

<pre><code>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 &lt;module&gt;
     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 &lt;module&gt;
     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 &lt;module&gt;
     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 &lt;module&gt;
     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
</code></pre>

<p>wsgi.py:</p>

<pre><code>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()
</code></pre>

<p>-gns</p>

<p>Thanks to @Graham Dumpleton for helping me in the comments. I had compiled mod_wsgi while python 2.7 was installed and I thought the virtualenv was enough for python 3.4, but I needed to remove python 2 and recompile mod_wsgi.</p>

<p>-gns</p>

python django sqlite sqlite3 mod-wsgi