Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Using Databases in Python Our Diary App Doing Data Entry

YiSzen Tang
YiSzen Tang
2,221 Points


I can't do sqlite3 diary.db on python (not on workspaces) the error says: 'sqlite3' is not recognized as an internal or external command, operable program or batch file.

1 Answer

James J. McCombie
.a{fill-rule:evenodd;}techdegree seal-36
James J. McCombie
Python Web Development Techdegree Graduate 21,199 Points


you would need to actually download SQlite itself to do this I believe. The python module sqlite3 provides an interface only.

that being said you can still interact with sqlite3 databases, and in fact create them using the module. To do this, you do:

import sqlite3

# this connects to or creates the database
db = sqlite3.connect('diary.db')

# creates a cursor object which you will use to interact with the database
c = db.cursor()

# execute SQL queries as an example
c.execute(INSERT SQL HERE)
# save the changes

you may also consider installing an ORM (object-relational mapping) type package, like pewee, or SQLalchemy. Pewee will be covered if you do the python-flask lessons, and its nice to use - I would recommend reading the docs - https://peewee.readthedocs.io/en/latest - if only to get an idea of what it does.