Error importing dbapi2...

376 views
Skip to first unread message

Fred Stluka

unread,
Aug 25, 2014, 9:31:10 AM8/25/14
to django...@googlegroups.com
I'm getting error:

django.core.exceptions.ImproperlyConfigured:
Error loading either pysqlite2 or sqlite3 modules
(tried in that order): cannot import name dbapi2

Any suggestions?

Details:

My settings.py contains:
DATABASE = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': '/Users/fred/fred/HHL/HHLWeb/sqlite3.db'
}
}

Works fine with other DBs (MySQL, MS SQL Server, etc.), but now
I'm trying to switch to SQLite for faster testing.

From the command line, I can see that sqlite3 is installed
(by default as part of the Django install), but seems to not
contain dbapi2:

>>> import sqlite3
>>> from sqlite3 import dbapi2
Traceback (most recent call last):
File "<console>", line 1, in <module>
ImportError: cannot import name dbapi2

Any ideas for me? Any suggestions on how to narrow down
the problem? Any more info I should give you?

Thanks!
--Fred

Camilo Torres

unread,
Aug 27, 2014, 10:53:51 AM8/27/14
to django...@googlegroups.com
If you are running inside a virtualenv, assure you have the sqlite3 module installed inside the v-env, or run toggleglobalsitepackages inside the v-env.

Fred Stluka

unread,
Aug 29, 2014, 2:58:27 PM8/29/14
to django...@googlegroups.com
I figured it out. 

Details:

I had set environment variable PYTHONPATH to help Django
find the sql_server.pyodbc files needed to make a connection
to a Microsoft SQL Server DB.  This was keeping SQLite from
working properly.  When I cleared the environment variable,
SQLite works fine.

I now get no errors when I do:

    >>> import sqlite3
    >>> from sqlite3 import dbapi2

and I no longer get the error about dbapi2 when I run my
regression tests via Django.

To get the sql_server.pyodbc file to be found, I now use a
symlink:
    % ln -s django/db/backends/sql_server \
             ~/python/virtualenvs/hhl/lib/python2.7/site-packages/sql_server
instead of setting PYTHONPATH:
    % setenv PYTHONPATH ~/python/virtualenvs/hhl/lib/python2.7/site-packages/django/db/backends

FYI,
--Fred
Fred Stluka -- mailto:fr...@bristle.com -- http://bristle.com/~fred/
Bristle Software, Inc -- http://bristle.com -- Glad to be of service!
Open Source: Without walls and fences, we need no Windows or Gates.
Reply all
Reply to author
Forward
0 new messages