Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No module named 'psycopg2'

Tags:

python

pip

django

I Installed psycopg2 using pip

C:\Users\username>python -m pip install psycopg2

Adjusted my settings to:

DATABASES = {
  'default': {
    'ENGINE': 'django.db.backends.postgresql_psycopg2', # also tried: django.db.backends.postgresql
    'NAME': 'name',
    'USER': 'user',
    'PASSWORD': 'my_password',
    'HOST': 'localhost',
    'PORT': '5432',
   }
}

When I attempt to run the server:

import psycopg2 as Database ImportError:

No module named 'psycopg2'

So I ran this again and got:

python -m pip install psycopg2 Requirement already satisfied (use --upgrade to upgrade): psycopg2 in ...

So what have I done wrong? I am new to Django

like image 482
Jonnny Avatar asked Nov 25 '16 16:11

Jonnny


2 Answers

There is a possibility that you have two versions of python installed and python2-pip is aliased as pip while python3-pip is aliased as pip3.

Make sure you are using right version with python and pip.

So the command would be:

pip3 install psycopg2
like image 118
Morishiri Avatar answered Sep 26 '22 04:09

Morishiri


You can try

pip install psycopg2-binary
like image 27
Hardik Patel Avatar answered Sep 22 '22 04:09

Hardik Patel