1

Very aware there are similar questions out there. I have had a sift through answers but nothing seems to be working... I'll explain from the beginning so hopefully someone can help. I am using python 3.8 on mac.

As title says, trying to connect a new django project to a postgresql database. I have installed the postgresql app (as well as pgadmin 4 for monitoring). I've updated my settings.py file as follows:

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

I've then gone into terminal to run python manage.py migrate to make the initial migrations, but receive the following: Error loading psycopg2 module: No module named 'psycopg2'.

Obviously, I then followed the instructions online and used pip install psycopg2-binary, successfully installing psycopg2-binary in:

/Users/Pete/Library/Python/2.7/lib/python/site-packages (2.8.6)

and also pip3 install psycopg2-binary, successfully installing psycopg2-binary in:

/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (2.8.6)

But I still receive the SAME error above.

Really quite stuck and would greatly appreciate any help!

Thanks.

1 Answer 1

1

So, after a couple hours of more searching, I finally came across an answer that worked. However, I am stumped as to why this worked. Would someone be able to explain?

The process that worked:

  • activate pipenv
  • run command PATH="/Applications/Postgres.app/Contents/Versions/latest/bin:$PATH"
  • install psycopg2-binary AGAIN
  • makemigrations
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.