Trouble with pip install psycopg2

Trying to learn Django. Followed the tutorial and created my virtual environment. Now I'm trying to install psycopg2. I can install psycopg2-binary, but I've been told for "psycopg2-binary is good for development and testing but it is advised to use psycopg2 for production". So I'd like to figure this out.

In my venv I'm running pip install psycopg2 it starts with this:

Collecting psycopg2
  Using cached psycopg2-2.8.6.tar.gz (383 kB)
Using legacy 'setup.py install' for psycopg2, since package 'wheel' is not installed.
Installing collected packages: psycopg2
    Running setup.py install for psycopg2 ... error

Then gives this error:

ERROR: Command errored out with exit status 1:
     command: /Users/Me/Documents/Learn/PythonDjango/dev/project/venv/bin/python3 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/hf/9bs1zgkx5pj9gt84snhwrq780000gn/T/pip-install-atdy12xg/psycopg2_cd32e59009264d2bbf87b0a9def98b4e/setup.py'"'"'; __file__='"'"'/private/var/folders/hf/9bs1zgkx5pj9gt84snhwrq780000gn/T/pip-install-atdy12xg/psycopg2_cd32e59009264d2bbf87b0a9def98b4e/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/hf/9bs1zgkx5pj9gt84snhwrq780000gn/T/pip-record-30vttiiv/install-record.txt --single-version-externally-managed --compile --install-headers /Users/me/Documents/Learn/PythonDjango/dev/project/venv/include/site/python3.9/psycopg2
         cwd: /private/var/folders/hf/9bs1zgkx5pj9gt84snhwrq780000gn/T/pip-install-atdy12xg/psycopg2_cd32e59009264d2bbf87b0a9def98b4e/

Then it's a long list of generated warnings. I've done some research and I've been unable to get it to work. Running Python 3.9.0 on macOS Big Sur 11.2.1


on Big Sur (MacOS) I was finally able to install this tonight using the following (had the same issues as you):

(install homebrew before this command if you don't have it already)

brew install openssl
export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"

then finally.......

pip3 install psycopg2