0

I am new to both python and django. I am trying to get python 3.4 and django 1.6.4 working within a pyvenv-3.4 environment on Linux Mint Mate 13. I followed the procedures of Using a virtual environment with Python 3.4 for "Building Python 3.4 from source" and "Using pyvenv-3.4". Then following the Django tutorial at Writing your first Django app, I was able to create "mysite" with startproject. But the command "python manage.py runserver" failed with django.core.exceptions. ImproperlyConfigured: Error loading either pysqlite2 or sqlite3 modules (tried in that order): No module named '_sqlite3'

Sorry, I do not recall why I resorted to compiling from source, but it may be that I was unable to find pyvenv in the standard Ubuntu downloads using apt-get. In any case, the Makefile for the source distribution does not have an "uninstall" target, so it seems I am stuck with whatever make installed, and without a plan for what to do next to actually get pyvenv-python-django working.

I am updating this post by attaching the full error:

$ python manage.py runserver
Traceback (most recent call last):
  File "/local/djenv/lib/python3.4/site-packages/django/db/backends/sqlite3/base.py", line 30, in <module>
    from pysqlite2 import dbapi2 as Database
ImportError: No module named 'pysqlite2'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/local/djenv/lib/python3.4/site-packages/django/db/backends/sqlite3/base.py", line 32, in <module>
    from sqlite3 import dbapi2 as Database
  File "/usr/local/lib/python3.4/sqlite3/__init__.py", line 23, in <module>
    from sqlite3.dbapi2 import *
  File "/usr/local/lib/python3.4/sqlite3/dbapi2.py", line 26, in <module>
    from _sqlite3 import *
ImportError: No module named '_sqlite3'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/local/djenv/lib/python3.4/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "/local/djenv/lib/python3.4/site-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/local/djenv/lib/python3.4/site-packages/django/core/management/base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/local/djenv/lib/python3.4/site-packages/django/core/management/base.py", line 280, in execute
    translation.activate('en-us')
  File "/local/djenv/lib/python3.4/site-packages/django/utils/translation/__init__.py", line 130, in activate
    return _trans.activate(language)
  File "/local/djenv/lib/python3.4/site-packages/django/utils/translation/trans_real.py", line 188, in activate
    _active.value = translation(language)
  File "/local/djenv/lib/python3.4/site-packages/django/utils/translation/trans_real.py", line 177, in translation
    default_translation = _fetch(settings.LANGUAGE_CODE)
  File "/local/djenv/lib/python3.4/site-packages/django/utils/translation/trans_real.py", line 159, in _fetch
    app = import_module(appname)
  File "/usr/local/lib/python3.4/importlib/__init__.py", line 104, 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 "/local/djenv/lib/python3.4/site-packages/django/contrib/admin/__init__.py", line 6, in <module>
    from django.contrib.admin.sites import AdminSite, site
  File "/local/djenv/lib/python3.4/site-packages/django/contrib/admin/sites.py", line 4, in <module>
    from django.contrib.admin.forms import AdminAuthenticationForm
  File "/local/djenv/lib/python3.4/site-packages/django/contrib/admin/forms.py", line 6, in <module>
    from django.contrib.auth.forms import AuthenticationForm
  File "/local/djenv/lib/python3.4/site-packages/django/contrib/auth/forms.py", line 17, in <module>
    from django.contrib.auth.models import User
  File "/local/djenv/lib/python3.4/site-packages/django/contrib/auth/models.py", line 48, in <module>
    class Permission(models.Model):
  File "/local/djenv/lib/python3.4/site-packages/django/db/models/base.py", line 96, in __new__
    new_class.add_to_class('_meta', Options(meta, **kwargs))
  File "/local/djenv/lib/python3.4/site-packages/django/db/models/base.py", line 264, in add_to_class
    value.contribute_to_class(cls, name)
  File "/local/djenv/lib/python3.4/site-packages/django/db/models/options.py", line 124, in contribute_to_class
    self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
  File "/local/djenv/lib/python3.4/site-packages/django/db/__init__.py", line 34, in __getattr__
    return getattr(connections[DEFAULT_DB_ALIAS], item)
  File "/local/djenv/lib/python3.4/site-packages/django/db/utils.py", line 198, in __getitem__
    backend = load_backend(db['ENGINE'])
  File "/local/djenv/lib/python3.4/site-packages/django/db/utils.py", line 113, in load_backend
    return import_module('%s.base' % backend_name)
  File "/usr/local/lib/python3.4/importlib/__init__.py", line 104, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/local/djenv/lib/python3.4/site-packages/django/db/backends/sqlite3/base.py", line 35, in <module>
    raise ImproperlyConfigured("Error loading either pysqlite2 or sqlite3 modules (tried in that order): %s" % exc)
django.core.exceptions.ImproperlyConfigured: Error loading either pysqlite2 or sqlite3 modules (tried in that order): No module named '_sqlite3'
  • Looks like a duplicate of a question asked here: http://stackoverflow.com/questions/20126475/importerror-no-module-named-sqlite3-in-python3-3 – crooksey May 10 '14 at 17:40
  • Thanks for your comment, but that post, which I had read previous to posting mine, does not address how to access sqlite3 from within the pyvenv virtual environment. – RazzleDazzleM May 10 '14 at 18:06
  • Do you get any errors when accessing sqlite3 from outside the pyenv environment? – ebarr May 10 '14 at 18:29
  • Outside the pyvenv project environment, the runserver command does indeed start the server for the tutorial project. – RazzleDazzleM May 10 '14 at 21:00
  • What I said in the previous comment is irrelevant. That used python 2. Inside or outside the environment, entering sqlite3 at the command prompt brings up sqlite3. – RazzleDazzleM May 10 '14 at 21:13
  • Does this post answer your question: https://stackoverflow.com/questions/10784132/django-no-module-named-sqlite3 – Mark Folashade Sep 20 '14 at 14:06

1 Answers1

0

It sounds like you didn't have the SQLite development libraries installed at the time you built CPython from source. The build process conditionally includes some features based the availability of underlying development libraries.

On Debian GNU/Linux and derivatives, install libsqlite3-dev. Then re-run ./configure, make and make install.

Ben Sturmfels
  • 1,303
  • 13
  • 22