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 trialJames J. McCombie
Python Web Development Techdegree Graduate 21,199 Pointscant run sqlite3 from powershell
Hi,
trying to work through the database section in learn flask track.
I can create the students.py file, and it creates a file called students.db.
I cannot however, run sqlite3 to do any of the additional tasks done during the video lesson.
sqlite3 is not recognized as the name of a cmdlet, function etc error when tried in powershell. In the Python shell I get an invalid syntax error when typing 'sqlite3 students.py'
it seems that python has sqlite3 module installed in Python35-32\lib\sqlite3\init.py, this shows when I type sqlite3 into the python shell alone.
I think I need to add SQLite3 to PATH?
5 Answers
Chris Freeman
Treehouse Moderator 68,457 PointsCorrect. sqlite3
must be installed in an existing directory on your PATH or the install directory must be added to your PATH.
James J. McCombie
Python Web Development Techdegree Graduate 21,199 Pointsumm, you might need someone with a bit more expertise, but if you want to just create a db using peewee and SQLite, lets call the database students.db as in your error report:
from peewee import *
DATABASE = SqliteDatabase('students.db')
Model classes are the database tables, a model instance creates a row in the table, and a field instance is a column in the table.
class Student(Model):
studentName = CharField()
studentCourse = CharField()
class Meta:
database = DATABASE
DATABASE.connect()
DATABASE.create_tables([Student])
# creating a student entry
# I am creating a variable to hold the instance, and then calling save on it
aStudent = Student(studentName = 'first student', studentCourse = '101')
aStudent.save()
I dont know if that is helpful but maybe it is...
[MOD: added ```python markdown formating -cf]
James J. McCombie
Python Web Development Techdegree Graduate 21,199 Pointshmm, not sure what happened there....
Matthew Goodman
12,786 Pointschrisfreeman3 you sir are correct thanks so much, I think was just along day yesterday many thanks really appreciate the help. one last thing I cannot seem to check in the DB using the CMD when I type sqlite3 students.db, get error? any ideas on this thanks again.
justlevy
6,326 PointsI solved this issue on a Windows 64 bit. This was confusing for me since I understood Python came preinstalled with SQLITE3.
I did have to create a PATH. However, first I had to download SQLITE3 files 'sqlite-tools-win32-x86-3360000.zip' and 'sqlite-dll-win64-x64-3360000.zip'. I believe you need both. As mentioned, I'm running 64 bit but I still needed to download that first package even though it says win32. That download includes the CLI executable (.exe).
After unzipping all the files to the same directory I had to set a PATH. Close and reopen Visual Studio Code and Terminals. Type 'sqlite3' and it should start the CLI.
Hope this is helpful to someone. More info here: https://www.sqlitetutorial.net/download-install-sqlite/
James J. McCombie
Python Web Development Techdegree Graduate 21,199 PointsJames J. McCombie
Python Web Development Techdegree Graduate 21,199 PointsThank you Chris,
any advice on how to do this? I have tried to set a path via the powershell command line and through the GUI, but no luck.
the sqlite3 database is included with python3, is this the problem? there is no .exe file.
James
Chris Freeman
Treehouse Moderator 68,457 PointsChris Freeman
Treehouse Moderator 68,457 PointsThe python
sqlite
module provides a programmatic way an interface a sqlite database. It does not have an interactive interface. To get this you must download windows version of an sqlite executable. Once downloaded and installed, thePATH
variable can be changed to add thesqlite3
install directory (see instructions)Matthew Goodman
12,786 PointsMatthew Goodman
12,786 PointsPlease help been trying most of the day to get a DB to work tried MySql and sqlite3 which comes with Python yet not matter what i do or google nothing works tried the paths everything ? is there a DB that will work im now looking at mamp but done nothing as yet. just need some help. thanks
the error on my latest try.
following the video to the letter.
[MOD: fixed formating -cf]
Chris Freeman
Treehouse Moderator 68,457 PointsChris Freeman
Treehouse Moderator 68,457 PointsMatthew Goodman, don't confuse
Model.create_table()
withDATABASE.create_tables()
. you need the latter (plural) method when working with the database. (see docs)