Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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,137 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.