Reputation: 5039
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
Upvotes: 7
Views: 29203
Reputation: 5371
I found that I was unable to import psycopg2
because I had created my virtualenv like this:
$ virtualenv -p python3 .venv
as soon as I change this to:
$ virtualenv .venv
Everything worked!
Upvotes: 0
Reputation: 1
Install below dependency before installing psycopg2
apt-get install libpq-dev
Now install:
pip install psycopg2
Give the below command to generate DB for your Django config
python manage.py migrate
Upvotes: 0
Reputation: 5587
It is possible that while following the installation tutorial you installed virtualenv
, created some environment (like env1
) and followed on to install django on that environment.
If so, than you are running django on that environment as well (otherwise it would not be installed). In order to install modules you need to first activate the environment and then use pip
.
Upvotes: 3
Reputation: 884
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
Upvotes: 11
Reputation: 19826
You may need to install the package from whl
file, try the below command:
pip install psycopg2-2.6.2-cp27-cp27m-win_amd64.whl
You can download this package from http://www.lfd.uci.edu/~gohlke/pythonlibs/
Upvotes: 4