0

I have read the Django documentation (For reference, https://docs.djangoproject.com/en/1.3/intro/tutorial01/), but I'm still having issues setting up a Django project to work with a database. Because I'm new to web development, I figured I would start with SQLite for development since I'm not putting anything into production yet and don't have much experience with databases. (I would be fine starting with MySQL or PostgreSQL though.)

In my Django project folder, I know I need to edit the settings.py folder to specify the database and a few other things. The problem is that when I run python manage.py syncdb in terminal, it fails with this message:

django.core.exceptions.ImproperlyConfigured: Error loading either pysqlite2 
or sqlite3 modules (tried in that order): No module named _sqlite3

I am assuming part of my problem is that I installed Python (2.7) from source code (explained in-depth in How would I build python myself from source code on Ubuntu?), yet my terminal is probably defaulting to the Python installed by default on Ubuntu. Or I suppose it could be that the Python (2.7) I built from source code somehow wasn't linked to SQLite. Or I suppose it could be that I need to specify an SQLite file in settings.py under the NAME item in DATABASES, although I'm pretty sure that isn't necessary for SQLite.

Can anyone identify the culprit? How would I remedy this as a long-term solution (i.e. Is there any way I can remove the ambiguity of having two co-existing Python installations on Ubuntu?) Most importantly, what do I need to do to set up a working database?

Community
  • 1
  • 1
Brian Schmitz
  • 1,023
  • 1
  • 10
  • 19
  • 2
    http://stackoverflow.com/questions/1210664/no-module-named-sqlite3 – Ahmet Recep Navruz Nov 13 '11 at 21:39
  • Where is your custom Python installed? Just removed it from your `PATH` might solve the problem. – Fred Foo Nov 13 '11 at 21:40
  • Also if you are unsure whether you have installed pysqlite2 you can use easy_install to get it running properly. Just google for it. – Paul Nov 13 '11 at 21:43
  • Ahmet: Okay, well how would I recompile the Python I built from source code? larsmans: It's installed in /usr/local although I think the executable python2.7 is in /usr/local/bin. I don't know how to do that could you explain? Paul: Is pysqlite2 needed? (Just so you guys know I just started using Linux) – Brian Schmitz Nov 13 '11 at 21:48

1 Answers1

4

Do a 'sudo apt-get install libsqlite3-dev' and then recompile Python 2.7.

In the long term, to reduce ambiguity of co-existing Python installations and packages, I highly recommend installing pip, virtualenv, and virtualenvwrapper.

coffee-grinder
  • 26,940
  • 19
  • 56
  • 82