Postgres with Django - Improperly configured. Error : ImproperlyConfigured: Error loading psycopg2 module: No module named 'psycopg2'

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

python makemigrations

However I get the error

File "/Users/raj/Development/mywebsite/virtual/lib/python3.5/site-packages/django/db/backends/postgresql/", 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

    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': '..',

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 ?


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)

2 answers

  • answered 2018-07-12 07:43 seuling

    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

  • answered 2018-07-12 07:46 Jonhy Beebop

    Try to install psycorpg2 using this:

    pip install psycopg2-binary