简体   繁体   中英

How do I set up SQLite with a Django project?

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 (ie 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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM