0

I used the following on the cmd to try and open the sqlite command line interface, but somehow it is not recognised.

I can see the sqlite db has been created, so cannot see what I am doing wrong:

(env) E:\Python installation\myproject\myflaskproject>sqlite
'sqlite' is not recognized as an internal or external command,
operable program or batch file.

(env) E:\Python installation\myproject\myflaskproject>

I've also tried typing at the prompt: >>sqlite3

Still, the same error.

Compoot
  • 2,227
  • 6
  • 31
  • 63
  • Do you actually have sqlite3 installed? – Chase Jun 24 '20 at 22:51
  • What does `dir /S \sqlite3.*` return when executed on the drive the command is supposed to be? – aschipfl Jun 25 '20 at 10:50
  • Please take a look on [What is the reason for "X is not recognized as an internal or external command, operable program or batch file"?](https://stackoverflow.com/a/41461002/3074564) – Mofi Jun 25 '20 at 17:12

1 Answers1

4

download slqlit3

to download slqlit3 go to this url: https://www.sqlite.org/download.html

since your are working on windows platform, under Precompiled Binaries for Windows section download sqlite-tools-win64-x64-3320300.zip or sqlite-tools-win32-x86-3320300.zip if your are like me working on the very OLD windows 7 32bit architecture

you have to know sqlite3 is a standalone and executable file meaning sqlite3 don't require to be installed like other programs:

A bundle of command-line tools for managing SQLite database files, including the command-line shell program, the sqldiff.exe program, and the sqlite3_analyzer.exe program.

unzip the downloaded file the under C:\ for e.g. and rename the folder to C:\sqlite3 to make things simple.

now, if you open : C:\sqlite3, you'll find 3 executable files:

C:\sqlite3
  sqldiff.exe
  **sqlite3.exe**
  sqlite3_analyzer.exe

add an Environment Variable

  • open System Properties (see this post)
  • go to Advanced tab under System Properties and click Environment Variables
  • Under System Variables create those variables:
    • PYTHON_HOME = C:\Python37 (it depends where you already installed python and which version if you have multiple installations)
    • SQLITE_HOME = C:\sqlite3
  • go to User variables and add/append variables to PATH like so:
    • PATH = [..];%PYTHON_HOME%;%PYTHON_HOME%\Scripts;

open new console and check your current active python:

python --version

and then you can use sqlite3 command not sqlite (check the C:\sqlite3 installation folder):

(env) E:\Python installation\myproject\myflaskproject>sqlite
'sqlite' is not recognized as an internal or external command,
operable program or batch file.

(env) E:\Python installation\myproject\myflaskproject>sqlite3 -version
3.15.2 2016-11-28 19:13:37 bbd85d235f7037c6a033a9690534391ffeacecc8

now you can open the sqlite database file (e.g: data-dev.sqlite3 under /myflaskproject ) like

(env) E:\Python installation\myproject\myflaskproject>sqlite3 data-dev.sqlite3
SQLite version 3.15.2 2016-11-28 19:13:37
Enter ".help" for usage hints.
sqlite>

some quick useful sqlite commands

sqlite> .databases
seq  name             file

---  ---------------  ----------------------------------------------------------

0    main             E:\Python installation\myproject\myflaskproject\data-dev.sqlite3

sqlite> .tables
user
sqlite> .exit (to exit)

for more about sqlite have look at this site sqlitetutorial.net

cizario
  • 3,995
  • 3
  • 13
  • 27
  • I haven't downloaded it - but shouldn't it be packaged with flask. The tutorial followed doesn't explcitly download it... – Compoot Jun 25 '20 at 15:55
  • `Flask` is un-opinionated micro-framework that means `Flask` won’t make decisions for you, such as what database to use nor chipping an external executable (sqlite3.exe) and not even support for any database (builtin classes, libs) if you want, you can install an extension that extends `Flask` capabilities like the famous `Flask-SALAlchemy` – cizario Jun 25 '20 at 16:57
  • if my answer was useful for you consider accepting it. – cizario Jun 25 '20 at 16:58
  • I need to verify it works....thank you. Any thoughts on this: https://stackoverflow.com/questions/62579373/opening-python-file-with-idle-version-3-7-and-the-venv-has-3-8-installed-no – Compoot Jun 25 '20 at 16:59
  • (env) E:\Python installation\myproject\myflaskproject>pip install sqlite3 Collecting sqlite3 ERROR: Could not find a version that satisfies the requirement sqlite3 (from versions: none) ERROR: No matching distribution found for sqlite3 WARNING: You are using pip version 19.2.3, however version 20.1.1 is available. You should consider upgrading via the 'python -m pip install --upgrade pip' command. (env) E:\Python installation\myproject\myflaskproject> – Compoot Jun 25 '20 at 18:56
  • I can't follow your answer at all. You start by saying - on windows add an Environment variable!? Where is the sqlite3 path. Too much assumed, and I can't follow it I'm afraid. I tried pip install sqlite3 in the venv and it resulted in the above ERROR. – Compoot Jun 25 '20 at 18:58
  • `(env) E:\Python installation\myproject\myflaskproject>pip install sqlite3` you are doing things the wrong way. i'll update my answer in short, it's easy than you think – cizario Jun 25 '20 at 19:15