3

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)
4
  • Which python/django version do you use? And what's the result from pip freeze | grep psycopg2 ? Commented Jul 12, 2018 at 7:35
  • let me update my post Commented Jul 12, 2018 at 7:38
  • @seuling just updated my post Commented Jul 12, 2018 at 7:41
  • yes i am using virtualenv but i installed postgres using homebrew on a mac Commented Jul 12, 2018 at 7:42

2 Answers 2

9

Try to install psycorpg2 using this:

pip install psycopg2-binary

Sign up to request clarification or add additional context in comments.

Comments

4

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

1 Comment

yes that did the trick marked as the answer

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.