9

I'm using Windows, no virtualenv. I have psycopg2 installed with Pip, and the latest version of PostgreSQL installed as well.

When I run ./ manage.py dbshell, I get the following error:

CommandError: You appear not to have the 'psql' program installed or on your path.

When I run ./ manage.py dbshell psql, I get this:

usage: manage.py dbshell [-h] [--version] [-v {0,1,2,3}] [--settings SETTINGS]
                         [--pythonpath PYTHONPATH] [--traceback] [--no-color]
                         [--database DATABASE]
manage.py dbshell: error: unrecognized arguments: psql

I have read a few other posts on this error like this but I don't understand why this is not working for me. I have all the settings properly configured, and all the proper apps installed.

My settings.py:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'postgres',
        'USER': 'postgres',
        'PASSWORD': '********',
        'HOST': '127.0.0.1',
        'PORT': '5432',
    }
}

EDIT: I did not add Postgres's /bin folder into my PATH. I just did it and it is working now. Thanks to Daniel Roseman.

Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
Valachio
  • 1,025
  • 2
  • 18
  • 40

4 Answers4

5

In Windows I solved by adding this to PATH environment:

C:\Program Files\PostgreSQL\12\bin

then restart terminals and IDEs

Path Environment PATH

How to add a folder to Path environment variable in Windows

Jorge Dri
  • 51
  • 1
  • 4
0

For mac, run command brew install postgres.

In case, your machine don't have brew installed, follow this to install brew. Or run command

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
kartikmaji
  • 946
  • 7
  • 22
0

I got the same error on Windows 11:

python manage.py dbshell

CommandError: You appear not to have the 'psql' program installed or on your path.

Even though I installed "psycopg2":

pip install psycopg2

So, I added the path "C:\Program Files\PostgreSQL\<version>\bin" to Path of User variables or System variables which are under Environment Variables, then I could solve the error. *In my case, <version> is 14 as shown below:

C:\Program Files\PostgreSQL\14\bin
Super Kai - Kazuya Ito
  • 22,221
  • 10
  • 124
  • 129
-2

Is postgresql installed on your machine.

Apart from:

pip install psycopg2

you need to install postgres:

sudo apt-get install postgres