2

After installing and configuring postgres using an online tutorial. I am attempting to run the command

python manage.py makemigrations

However I get the error

...
...
File "/Users/raj/Development/mywebsite/virtual/lib/python3.5/site-packages/django/db/backends/postgresql/base.py", line 24, in <module>
    raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: No module named 'psycopg2'

This is in my settings.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': '..',
        'USER':"...",
        "PASSWORD":"...",
        "HOST":"localhost",
        "PORT":"5432",
    }
}

Now I came across this thread which suggests that there might be an import issue. However If i import the package in the terminal like this it doesnt complain

>>> import django.db.backends.postgresql_psycopg2
>>> 

Any suggestions on what I might be doing wrong here ?

Update:

The following command does not return anything

pip freeze | grep psycopg2

Also I am using Django 2.0.4

>>> import django
>>> django.VERSION
(2, 0, 4, 'final', 0)
Rajeshwar
  • 9,840
  • 21
  • 65
  • 137

2 Answers2

7

Try to install psycorpg2 using this:

pip install psycopg2-binary

Jonhy Beebop
  • 1,082
  • 1
  • 13
  • 26
3

psycopg2 is not installed in your env.

Make sure you use correct virtualenv (if use), and install psycopg2.

tye pip install psycopg2. (if using pip3, use pip3 install psycopg2).

ps. If you're in ubuntu, install other dependencies

sudo apt-get install build-dep python-psycopg2

seuling
  • 2,262
  • 1
  • 6
  • 19