[Baypiggies] Python & Django: No module named _sqlite3
Tom Simons
tom.simons at gmail.com
Mon Aug 16 19:43:10 CEST 2010
Python newbie here - I've been replacing our awk & ksh scripts for reports
with it. I liked the Django demo on Windows so much that I volunteered to
implement our tiny website using Django on RHEL AS5 Linux boxes.
Now I'm running into trouble getting Python, Django, & SQLite working on
RHEL AS5. I don't really require compiling from source, but I did so to get
the latest versions (& I thought Python > 2.5 came with SQLite already
installed).
What am I missing in the installs below? The Django "manage.py syncdb" gets
error "No module named _sqlite3".
Does Django installation require more than the link to
Python-2.7/lib/python2.7/site-packages?
$ tar xf Python-2.7.tgz #Install Python 2.7
$ cd Python-2.7
$ mkdir /apps/Python-2.7
$ chown simonst /apps/Python-2.7
$ ./configure --prefix=/apps/Python-2.7
$ make
$ sudo make install
$ export PATH=/apps/Python-2.7/bin:$PATH
$ python -V
Python 2.7
$ tar xzf sqlite-amalgamation-3.7.0.1.tar.gz #Install sqlite 3.7.0.1
$ cd sqlite-3.7.0.1
$ ./configure --prefix=/apps/sqlite-3.7.0
$ make
$ sudo make install
$ export PATH=/apps/sqlite-3.7.0/bin:$PATH
$ sqlite3 -version
3.7.0.1
$ sudo tar xzf Django-1.2.1.tar.gz -C /apps #Install Django 1.2.1
$ cd /apps/Django-1.2.1
$ sudo ln -s /apps/Django-1.2.1/django
/apps/Python-2.7/lib/python2.7/site-packages
$ export PATH=/apps/Django-1.2.1/django/bin:$PATH
$ django-admin.py --version
1.2.1
(see attachment for more detail)
$ django-admin.py startproject mysite #Start Django project
$ cd mysite
$ ./manage.py runserver #Show Django dev server is ok
$ ./manage.py startapp blog #Start Django Blog app
$ vi blog/models.py
$ vi settings.py
$ ./manage.py syncdb #Build database
Traceback (most recent call last):
File "./manage.py", line 11, in <module>
. . . . .
File
"/apps/Python-2.7/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py",
line 34, in <module>
raise ImproperlyConfigured("Error loading %s: %s" % (module, exc))
django.core.exceptions.ImproperlyConfigured: Error loading either pysqlite2
or sqlite3 modules (tried in that order): No module named _sqlite3
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/baypiggies/attachments/20100816/b172f83a/attachment.html>
-------------- next part --------------
$ tar xf Python-2.7.tgz #Install Python 2.7
$ cd Python-2.7
$ mkdir /apps/Python-2.7
$ chown simonst /apps/Python-2.7
$ ./configure --prefix=/apps/Python-2.7
$ make
$ sudo make install
$ export PATH=/apps/Python-2.7/bin:$PATH
$ python -V
Python 2.7
$ tar xzf sqlite-amalgamation-3.7.0.1.tar.gz #Install sqlite 3.7.0.1
$ cd sqlite-3.7.0.1
$ ./configure --prefix=/apps/sqlite-3.7.0
$ make
$ sudo make install
$ export PATH=/apps/sqlite-3.7.0/bin:$PATH
$ sqlite3 -version
3.7.0.1
$ sudo tar xzf Django-1.2.1.tar.gz -C /apps #Install Django 1.2.1
$ cd /apps/Django-1.2.1
$ sudo ln -s /apps/Django-1.2.1/django /apps/Python-2.7/lib/python2.7/site-packages
$ export PATH=/apps/Django-1.2.1/django/bin:$PATH
$ django-admin.py --version
1.2.1
$ django-admin.py startproject mysite #Start Django project
$ cd mysite
$ ./manage.py runserver #Show Django dev server is ok
Validating models...
0 errors found
Django version 1.2.1, using settings 'mysite.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
[16/Aug/2010 10:59:26] "GET / HTTP/1.1" 200 2051
< Ctl-C>
$ ./manage.py startapp blog #Start Django Blog app
$ vi blog/models.py
$ cat blog/models.py
from django.db import models
class BlogPost(models.Model):
title = models.CharField(max_length=150)
body = models.TextField()
timestamp = models.DateTimeField()
$ vi settings.py
$ diff settings.py settings.py_ORIG
14,15c14,15
< 'ENGINE': 'django.db.backends.sqlite3',
< 'NAME': '/var/db/django.db',
---
> 'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
> 'NAME': '', # Or path to database file if using sqlite3.
92c92,93
< 'django.contrib.admin',
---
> # Uncomment the next line to enable the admin:
> # 'django.contrib.admin',
$ ./manage.py syncdb #Build database
Traceback (most recent call last):
File "./manage.py", line 11, in <module>
execute_manager(settings)
File "/apps/Python-2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/apps/Python-2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/apps/Python-2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 257, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/apps/Python-2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 67, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/apps/Python-2.7/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/apps/Python-2.7/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 7, in <module>
from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal
File "/apps/Python-2.7/lib/python2.7/site-packages/django/core/management/sql.py", line 5, in <module>
from django.contrib.contenttypes import generic
File "/apps/Python-2.7/lib/python2.7/site-packages/django/contrib/contenttypes/generic.py", line 6, in <module>
from django.db import connection
File "/apps/Python-2.7/lib/python2.7/site-packages/django/db/__init__.py", line 75, in <module>
connection = connections[DEFAULT_DB_ALIAS]
File "/apps/Python-2.7/lib/python2.7/site-packages/django/db/utils.py", line 91, in __getitem__
backend = load_backend(db['ENGINE'])
File "/apps/Python-2.7/lib/python2.7/site-packages/django/db/utils.py", line 32, in load_backend
return import_module('.base', backend_name)
File "/apps/Python-2.7/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/apps/Python-2.7/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 34, in <module>
raise ImproperlyConfigured("Error loading %s: %s" % (module, exc))
django.core.exceptions.ImproperlyConfigured: Error loading either pysqlite2 or sqlite3 modules (tried in that order): No module named _sqlite3
More information about the Baypiggies
mailing list