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

Martin Pennock
3,651 PointsUsing databases in python: Modeling. 'sqlite3' is not recognized as an internal or external command
When trying to run the command, sqlite3 students.db (in command prompt on windows), I get the error: 'sqlite3' is not recognized as an internal or external command, operable program or batch file
4 Answers

andi mitre
Treehouse Guest TeacherStart by adding sqlite3 to your path, use this link for reference. http://stackoverflow.com/questions/10388354/sqlite-from-command-prompt-not-recognized-command

Chris Howell
Python Web Development Techdegree Graduate 49,703 PointsHi Martin,
So you are getting this error because sqlite3 is not a recognized Windows command. Python for that matter isnt even a recognized Windows command, until you installed it and during the install PATH variables were set to make command prompt recognize that command executable. But sqlite3 is not something you need to "install" as you did with Python.
Python has libraries that you can install using pip. sqlite3 would be considered one of these libraries, but even this is unnecessary because sqlite3 should of come with your Python installation. Therefore all you need to do, if YOU are trying to manually create that script file ( students.db ) is use a text editor and do File -> New File.
Or you can use a Windows Command such as NUL > students.db
which would create an empty file in the directory you are sitting in inside command prompt.
BUT neither of these should be necessary either. If you follow the scripts Kenneth is writing in that series where he does the imports for peewee and creates the initial Student Model.
# This is necessary to use SqliteDatabase, Model and any database Field
from peewee import *
# This will ensure a Sqlite database is named students.db
db = SqliteDatabase('students.db')
class Student(Model):
# ... code here for model
Docs for using Peewee and for this reference to SqliteDatabase
This of course is assuming you are following Kenneth's example in the series. But If you are trying to do your own thing without using peewee. And you need sqlite3 accessible in Command Prompt instead of accessing it through Python Shell then disregard these things. :)

Chris Howell
Python Web Development Techdegree Graduate 49,703 PointsYou can also interact with sqlite3 using Python without peewee by importing it.
import sqlite3
connection = sqlite3.connect(some_file)
where some_file is a string file-path to where the database file is on your local hard drive.
Some Docs on that as well.

Martin Pennock
3,651 PointsFrom your comment, I gather that I do not need to install sqlite3 as long as I have installed python (I have 3.5.2 installed)
I followed Kenneth's video as you said. Here is the exact code I have from the video:
from peewee import *
import sqlite3
db = SqliteDatabase('students.db')
class Student(Model):
username = CharField(max_length=225, unique=True)
points = IntegerField(default=0)
class Meta:
database = db
if __name__ == '__main__':
db.connect()
db.create_tables([Student], safe=True)
The students.db file was indeed created, but I still get the error.

Chris Howell
Python Web Development Techdegree Graduate 49,703 PointsAh, I think you are still getting a few concepts confused here. I will try to elaborate a little better on whats happening.
I am still slightly confused on the why of why you are trying to directly call a command sqlite3 students.db
? Did you see this done somewhere or can you explain what your goal is if you are trying to do different things from what kenneth is doing with peewee in the video?
** Here is a bit of elaboration **
Command Prompt belongs to Windows - Initially it comes with its own set of default commands you can call to interact with your OS or things like your directories. So things (in command prompt) like:
cd
or
rmdir
are commands: where cd
is meant to "Change Directory" and rmdir
is meant for "removing directories". Anytime you want to use "3rd party" commands something called an Environmental Variable must be set in order to point at that specific executable to be able to call it from command prompt. This exact setting of an Environmental Variable happened when you installed Python to give you the ability to type something like python --version
into the Command Prompt. python
is a command that Command Prompt knows how to get to, and --version
is a command that python knows how to access and give back to command prompt to display.
So anything Python related you do will almost always start with the command
python <somethinghere>
where <somethinghere> could be almost anything, another command or a script file you want to run.
Python has its OWN version of a command prompt called the Python Shell.
If you want to get into the Python Shell you can type python
in command prompt and you will see some Python versioning info and a date followed by this:
>>>
This is python waiting for commands.
In here you could essentially do everything you are doing in your Python script that you posted in that snippet of code. So you could type
>>> import sqlite3
no errors generally are a good sign. Now we can access sqlite3.

Sahar Nasiri
7,454 PointsCheck 2 things:
First, add sqlite3.dll to the root of you Python folder. For example, go to C:\Users\sahar\AppData\Local\Programs\Python\Python35 and past the sqlite3.dll file. (You need to download this file, and if you cannot please let me know so I email you the file).
Second, make sure that you have added the Python and Python Script path to you environment variables. if not: This PC, right click, properties, Advanced, Environment Variables, New, ... and the add "C:\Users\sahar\AppData\Local\Programs\Python\Python35" and "C:\Users\sahar\AppData\Local\Programs\Python\Python35\Scripts" as your path.
Please note that the addresses in for my computer, you have to change them.
Martin Pennock
3,651 PointsMartin Pennock
3,651 PointsSorry, but I have read through the link you provided, and cannot figure out how to add sqlite3 to my path on windows 10. Do I need to download sqlite3? As another has posted, this shouldn't be necessary as "sqlite3 should of come with your Python installation".
I have Python 3.5.2 installed. I downloaded the sqlite3.exe from their site and placed it in my directory but it still does not work.