0

I'd like to be issuing SQL commands via python manage.py dbshell but I get the error "CommandError: You appear not to have the 'sqlite3' program installed or on your path". From the python prompt I can import psycopg2 without getting any errors and psycopg2 appears to be in my python path.

I'm trying django and my settings.py specifies "ENGINE": "django.db.backends.postgresql_psycopg2"

Any help would be greatly appreciated,

Thanks, Julian

Julian Jordan
  • 11
  • 1
  • 4

3 Answers3

1

when you run ./manage.py dbshell psql or sqlite3 this command assumes the programs are on your PATH. this will simply calls the program name.

sqlite3

from Python itself dosen't contain a sqlite3 command. if you want to access from the command line you have to install SQLite library that includes a simple command-line utility named sqlite3. but without installing library you can create the db server because it doesn’t require running a separate server and sqlite3 itself a text based file.

If you are developing a simple project or something you don’t plan to deploy in a production environment, then use SQLite

in your case first install sqlite3 using sudo apt-get install sqlite3 libsqlite3-dev to access dbshell.

postgres

compare to sqlite3 this postgres needs package to initialize. postgresql need postgresql_psycopg2 package

Raja Simon
  • 10,126
  • 5
  • 43
  • 74
  • Hi - postgres is the database that I'm ultimately going to be using, so I'd like to stick with that rather than sqlite3. Running psql works fine from any directory so I guess that is on my PATH. As I mentioned, I think psycopg2 is also installed OK as I can run "import psycopg2" without errors from the python prompt. Running ./manage.py dbshell psql gives a list of errors culminating in: `output = self.handle(*args, **options) TypeError: handle() takes exactly 1 argument (7 given)` Thanks for your help – Julian Jordan Sep 26 '14 at 09:34
  • @JulianJordan you never mentioned in your question when running `dbshell psql` gives error` – Raja Simon Sep 26 '14 at 09:38
  • Hi - I didn't know until your helpful answer that I could specify psql on the end of `./manage.py dbshell` so that in itself has been helpful, as until then I'd been getting an error relating to sqlite3 (presumably the default option?) – Julian Jordan Sep 26 '14 at 09:42
  • Oh ,.. so now `dbshell psql` gives you this error `output = self.handle(*args, **options) TypeError: handle() takes exactly 1 argument (7 given)` am i right ? – Raja Simon Sep 26 '14 at 09:45
  • Hi - specifying the name of my database after dbshell psql gives a similar error: `output = self.handle(*args, **options) TypeError: handle() takes exactly 1 argument (8 given)` – Julian Jordan Sep 26 '14 at 10:48
  • @JulianJordan oh . okay .. let's give like this `dbshell psql --database=default` try default first if it's fails try actual db name.. – Raja Simon Sep 26 '14 at 10:50
  • 1
    Sorry that doesn't work either. My main aim at the moment is to get through the django tutorial so I've made a new setup using sqlite3 which "just works". Ultimately I'm going to have to use postgres but I think for now I'll use the easier db setup. Thanks for your suggestions :o) – Julian Jordan Sep 26 '14 at 14:02
  • @JulianJordan please read this questin before procede [http://stackoverflow.com/questions/17776709/setting-up-postgresql-with-django-project](http://stackoverflow.com/questions/17776709/setting-up-postgresql-with-django-project),. – Raja Simon Sep 26 '14 at 14:11
0

You need to install sqlite3 to be able to run dbshell

Installing the sqlite program should solve the problem:

sudo apt-get install sqlite3
geo_pythoncl
  • 927
  • 1
  • 7
  • 13
0

I think there is some confusion as to what dbshell does. From the documentation:

Runs the command-line client for the database engine specified in your ENGINE setting, with the connection parameters specified in your USER, PASSWORD, etc., settings.

  • For PostgreSQL, this runs the psql command-line client.
  • For MySQL, this runs the mysql command-line client.
  • For SQLite, this runs the sqlite3 command-line client.

This command assumes the programs are on your PATH so that a simple call to the program name (psql, mysql, sqlite3) will find the program in the right place. There’s no way to specify the location of the program manually.

Its not like manage.py shell, dbshell just runs the normal shell for the database configured, except it logs you in with the credentials in settings.py.

This means, if you are using postgresql, you need to have the psql command already installed in order for dbshell to work. This command is not part of Python, but comes with the postgresql server.

In order words - if all you have installed is psycopg2, the dbshell command will not work.

Burhan Khalid
  • 169,990
  • 18
  • 245
  • 284