Postgresql not working with Django? Can't install psycopg2?

Input data:

  1. Machine: Mac OS Mojave 10.14.6
  2. Python latest version
  3. Django latest version
  4. Postgresql latest version.
  5. psycopg2 is the latest version, but it doesn’t matter in my case.

Goal:
Interview Test: Write a small Django project using Postgresql.

Problem:
I installed Django with virtual environment without problems. Postgresql itself works and installs without problems. I was able to create user and db without error.

Tried to install psycopg2 gave error lines at 400-500. Ok, I was not at a loss and found an option in the official documentation: install the binary option. Ok, installed, everything is ok.

Then I changed the standard settings in settings.py to:
DATABASES = {
‘default’: {
‘ENGINE’: ‘django.db.backends.postgresql_psycopg2’,
‘NAME’: ‘labmedia_project’,
‘USER’: ‘labmedia_user’,
‘PASSWORD’: ‘qweasd’,
‘HOST’: ‘localhost’,
‘PORT’: 5432,
}
}
Excellent. Wrote two models, use makemigrations and writes to me that no changes were found.

Then a series of trial and error began. I have visited a total of 30+ sites, including foreign ones, with the hope of finding an answer. None of the suggested ones helped me: I changed the paths, tried to install via setup.py, etc.

Perhaps the problem is that most manuals write solutions for Linux. But even where they write for MacOS did not help either.

Regarding the binary: everything is fine, but it doesn’t work on its own. The installation is described on the official website, but a piece of code is written there:
import psycopg

# Connect to your postgres DB
conn = psycopg.connect("dbname=test user=postgres")

# Open a cursor to perform database operations
cur = conn.cursor()

# Execute a query
cur.execute("SELECT * FROM my_data")

# Retrieve query results
records = cur.fetchall()

Of course, nowhere is it written where to insert it. So I went to google, but no one describes how to use it, apparently everyone understands everything.

Questions:

  1. How can you fix the error? All the same, I want to have the full version.
  2. How to use the binary correctly? In a normal installation, it just doesn’t work like that.

P.S. I will attach the error screen, I will attach the error with a file or a link.

Hi!

I don’t have a Mac (I use Linux) but I struggled a fre times with this problem, so maybe I can help.

Why are you executing pip like this?

(venv) MacBook-Air-Makbuk:labmedia_project makbuk$ sudo PATH=$PATH:/Applications/Postgres.
app/Contents/Versions/9.3/bin pip install psycopg2

Again, I’m not a Mac user but I think you’re misunderstanding the functioning of a virtualenv.
Also why are you calling pip with sudo?

Have you installed the psycopg_binary?
Per the psycopg docs you have to execute pip install psycopg2-binary

Hope it helps! :+1: