psycopg / psycopg2

PostgreSQL database adapter for the Python programming language

Home Page:https://www.psycopg.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

psycopg2-binary fails to install on macOS Big Sur 11.0.1 and Python 3.9.0 (with possible workaround)

akurani opened this issue · comments

Environment:

  • macOS 11.0.1 (Big Sur)
  • Python 3.9.0 (installed via pyenv)

When I attempt to pip-install psycopg2-binary with in a venv, the installer instead tries to compile psycopg2 and fails for me as I don't have PostgreSQL installed:

$ pip install psycopg2-binary
Collecting psycopg2-binary
  Using cached psycopg2-binary-2.8.6.tar.gz (384 kB)
    ERROR: Command errored out with exit status 1:
     command: /Users/amar/test3/.venv/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/73/97rprb4s6qz9qc7n8xy0vt800000gn/T/pip-install-jo9na1rs/psycopg2-binary/setup.py'"'"'; __file__='"'"'/private/var/folders/73/97rprb4s6qz9qc7n8xy0vt800000gn/T/pip-install-jo9na1rs/psycopg2-binary/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/73/97rprb4s6qz9qc7n8xy0vt800000gn/T/pip-pip-egg-info-mgvwjdyx
         cwd: /private/var/folders/73/97rprb4s6qz9qc7n8xy0vt800000gn/T/pip-install-jo9na1rs/psycopg2-binary/
    Complete output (23 lines):
    running egg_info
    creating /private/var/folders/73/97rprb4s6qz9qc7n8xy0vt800000gn/T/pip-pip-egg-info-mgvwjdyx/psycopg2_binary.egg-info
    writing /private/var/folders/73/97rprb4s6qz9qc7n8xy0vt800000gn/T/pip-pip-egg-info-mgvwjdyx/psycopg2_binary.egg-info/PKG-INFO
    writing dependency_links to /private/var/folders/73/97rprb4s6qz9qc7n8xy0vt800000gn/T/pip-pip-egg-info-mgvwjdyx/psycopg2_binary.egg-info/dependency_links.txt
    writing top-level names to /private/var/folders/73/97rprb4s6qz9qc7n8xy0vt800000gn/T/pip-pip-egg-info-mgvwjdyx/psycopg2_binary.egg-info/top_level.txt
    writing manifest file '/private/var/folders/73/97rprb4s6qz9qc7n8xy0vt800000gn/T/pip-pip-egg-info-mgvwjdyx/psycopg2_binary.egg-info/SOURCES.txt'
    
    Error: pg_config executable not found.
    
    pg_config is required to build psycopg2 from source.  Please add the directory
    containing pg_config to the $PATH or specify the full executable path with the
    option:
    
        python setup.py build_ext --pg-config /path/to/pg_config build ...
    
    or with the pg_config option in 'setup.cfg'.
    
    If you prefer to avoid building psycopg2 from source, please install the PyPI
    'psycopg2-binary' package instead.
    
    For further information please check the 'doc/src/install.rst' file (also at
    <https://www.psycopg.org/docs/install.html>).

I can get around this using the SYSTEM_VERSION_COMPAT=1 env var. That sets the macOS version to 10.16 instead of 11.0:

$ SYSTEM_VERSION_COMPAT=1 pip install psycopg2-binary
Collecting psycopg2-binary
  Downloading psycopg2_binary-2.8.6-cp39-cp39-macosx_10_9_x86_64.macosx_10_9_intel.macosx_10_10_intel.macosx_10_10_x86_64.whl (1.5 MB)
     |████████████████████████████████| 1.5 MB 5.1 MB/s 
Installing collected packages: psycopg2-binary
Successfully installed psycopg2-binary-2.8.6

Note, I haven't tested using this psycopg2-binary on Big Sur yet. I'm running into install issues with Pillow that I'm sorting out too. (How I wish I didn't upgrade to Big Sur yet!)

Probably the last and greatest Mac OS is not compatible with wheels packages.

You should hear from the Python Package Authority, or from Apple.

Hi, I am using Catalina (10.15.7) and I also had the same issue Error: pg_config executable not found..

In our case the issue went away updating the version we were using of psycopg2. We were using python 3.7 with pyscopg2 2.7.5 and everything was working fine. We are now updating python to 3.9 and when trying to install requirements we found that psycopg could not find pg_config. This error also happened if trying to install 2.7.5 with python 3.8.

Allowing the version to be ~=2.8.0 fixed it and now it can install properly. This has nothing to do with the original issue raised but I just wanted to leave it here in case it triggers some thought and someone arrives here with the same issue I had before :)

Hey, I just got the same message today. I'm using fedora 33 and python 3.9 and when I wanted to install psycopg2-binary using pip install psycopg2-binary it complained about not having pg_config executable binary.

Here is the full log:

Collecting psycopg2-binary==2.7.7
  Downloading psycopg2-binary-2.7.7.tar.gz (428 kB)
     |████████████████████████████████| 428 kB 451 kB/s 
    ERROR: Command errored out with exit status 1:
     command: /home/ehsan/.virtualenvs/CQ/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-5_22rja8/psycopg2-binary/setup.py'"'"'; __file__='"'"'/tmp/pip-install-5_22rja8/psycopg2-binary/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-1utvtzmt
         cwd: /tmp/pip-install-5_22rja8/psycopg2-binary/
    Complete output (23 lines):
    running egg_info
    creating /tmp/pip-pip-egg-info-1utvtzmt/psycopg2_binary.egg-info
    writing /tmp/pip-pip-egg-info-1utvtzmt/psycopg2_binary.egg-info/PKG-INFO
    writing dependency_links to /tmp/pip-pip-egg-info-1utvtzmt/psycopg2_binary.egg-info/dependency_links.txt
    writing top-level names to /tmp/pip-pip-egg-info-1utvtzmt/psycopg2_binary.egg-info/top_level.txt
    writing manifest file '/tmp/pip-pip-egg-info-1utvtzmt/psycopg2_binary.egg-info/SOURCES.txt'
    
    Error: pg_config executable not found.
    
    pg_config is required to build psycopg2 from source.  Please add the directory
    containing pg_config to the $PATH or specify the full executable path with the
    option:
    
        python setup.py build_ext --pg-config /path/to/pg_config build ...
    
    or with the pg_config option in 'setup.cfg'.
    
    If you prefer to avoid building psycopg2 from source, please install the PyPI
    'psycopg2-binary' package instead.
    
    For further information please check the 'doc/src/install.rst' file (also at
    <http://initd.org/psycopg/docs/install.html>).
    
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

@hsnprsd you are trying to install 2.7.7, which was released way before Python 3.9. We don't have a time machine: MR for time travel features are well received.

Binary packages for Python 3.9 for linux and windows are available only from 2.8.6 on.

Mac OS has released a new version and as per usual they have broken everything they could. So this ticket is about MacOS, not windows and linux. I'd appreciate if it remained that way.

@dvarrazzo Sorry, you are right. I wasn't aware I am installing an old version of psycopg.

I found this problem was resolved by upgrading pip:

python3 -m pip install --upgrade pip

Running pip prints warnings to upgrade.

I am using Mac os big sure and this works for me.
install openssl using brew

brew install openssl
after that export these variables in the terminal.

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

then finally install psycopg2

pip3 install psycopg2

I am using Mac os big sure and this works for me.
install openssl using brew

brew install openssl
after that export these variables in the terminal.

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

then finally install psycopg2

pip3 install psycopg2

Hi @Nkarnaud , I am using Big Sur on Apple silicon. This doesn't work for me. Can you help? :(

I am using Mac os big sure and this works for me.
install openssl using brew
brew install openssl
after that export these variables in the terminal.

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

then finally install psycopg2
pip3 install psycopg2

Hi @Nkarnaud , I am using Big Sur on Apple silicon. This doesn't work for me. Can you help? :(

Hi @shreyagupta30, can you share the error you are having?

I am using Mac os big sure and this works for me.
install openssl using brew
brew install openssl
after that export these variables in the terminal.

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

then finally install psycopg2
pip3 install psycopg2

Hi @Nkarnaud , I am using Big Sur on Apple silicon. This doesn't work for me. Can you help? :(

Hi @shreyagupta30, can you share the error you are having?

ERROR: Command errored out with exit status 1: /Library/Developer/CommandLineTools/usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/j8/2nzz29zn0439c37m5klxf9mh0000gn/T/pip-install-nyhue42a/psycopg2/setup.py'"'"'; __file__='"'"'/private/var/folders/j8/2nzz29zn0439c37m5klxf9mh0000gn/T/pip-install-nyhue42a/psycopg2/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/j8/2nzz29zn0439c37m5klxf9mh0000gn/T/pip-record-v6umrnqf/install-record.txt --single-version-externally-managed --compile Check the logs for full command output.

Here @Nkarnaud

I am using Mac os big sure and this works for me.
install openssl using brew
brew install openssl
after that export these variables in the terminal.

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

then finally install psycopg2
pip3 install psycopg2

Hi @Nkarnaud , I am using Big Sur on Apple silicon. This doesn't work for me. Can you help? :(

Hi @shreyagupta30, can you share the error you are having?

ERROR: Command errored out with exit status 1: /Library/Developer/CommandLineTools/usr/bin/python3 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/j8/2nzz29zn0439c37m5klxf9mh0000gn/T/pip-install-nyhue42a/psycopg2/setup.py'"'"'; __file__='"'"'/private/var/folders/j8/2nzz29zn0439c37m5klxf9mh0000gn/T/pip-install-nyhue42a/psycopg2/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/j8/2nzz29zn0439c37m5klxf9mh0000gn/T/pip-record-v6umrnqf/install-record.txt --single-version-externally-managed --compile Check the logs for full command output.

Here @Nkarnaud

check this it may be of help. https://stackoverflow.com/questions/62877588/psycopg2-gives-error-while-installing-in-macos-catalina-10-15-5

Adding that I'm having similar issues with the following:

  • Apple M1
  • Big Sur 11.2
  • Python 3.8.2
  • Pip 21.0.1
$ pip install psycopg2-binary --no-cache-dir
Collecting psycopg2-binary
  Downloading psycopg2-binary-2.8.6.tar.gz (384 kB)
     |████████████████████████████████| 384 kB 25.7 MB/s 
    ERROR: Command errored out with exit status 1:
     command: /Users/m1/company-app/api/.venv/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/9y/z49zz0951k3gkbnp0mb4f13w0000gn/T/pip-install-ccqum8r8/psycopg2-binary_08a234e704634109bb83b0b7c6b8ca28/setup.py'"'"'; __file__='"'"'/private/var/folders/9y/z49zz0951k3gkbnp0mb4f13w0000gn/T/pip-install-ccqum8r8/psycopg2-binary_08a234e704634109bb83b0b7c6b8ca28/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/9y/z49zz0951k3gkbnp0mb4f13w0000gn/T/pip-pip-egg-info-ybwazise
         cwd: /private/var/folders/9y/z49zz0951k3gkbnp0mb4f13w0000gn/T/pip-install-ccqum8r8/psycopg2-binary_08a234e704634109bb83b0b7c6b8ca28/
    Complete output (23 lines):
    running egg_info
    creating /private/var/folders/9y/z49zz0951k3gkbnp0mb4f13w0000gn/T/pip-pip-egg-info-ybwazise/psycopg2_binary.egg-info
    writing /private/var/folders/9y/z49zz0951k3gkbnp0mb4f13w0000gn/T/pip-pip-egg-info-ybwazise/psycopg2_binary.egg-info/PKG-INFO
    writing dependency_links to /private/var/folders/9y/z49zz0951k3gkbnp0mb4f13w0000gn/T/pip-pip-egg-info-ybwazise/psycopg2_binary.egg-info/dependency_links.txt
    writing top-level names to /private/var/folders/9y/z49zz0951k3gkbnp0mb4f13w0000gn/T/pip-pip-egg-info-ybwazise/psycopg2_binary.egg-info/top_level.txt
    writing manifest file '/private/var/folders/9y/z49zz0951k3gkbnp0mb4f13w0000gn/T/pip-pip-egg-info-ybwazise/psycopg2_binary.egg-info/SOURCES.txt'
    
    Error: pg_config executable not found.
    
    pg_config is required to build psycopg2 from source.  Please add the directory
    containing pg_config to the $PATH or specify the full executable path with the
    option:
    
        python setup.py build_ext --pg-config /path/to/pg_config build ...
    
    or with the pg_config option in 'setup.cfg'.
    
    If you prefer to avoid building psycopg2 from source, please install the PyPI
    'psycopg2-binary' package instead.
    
    For further information please check the 'doc/src/install.rst' file (also at
    <https://www.psycopg.org/docs/install.html>).
    
    ----------------------------------------
WARNING: Discarding https://files.pythonhosted.org/packages/fc/51/0f2c6aec5c59e5640f507b59567f63b9d73a9317898810b4db311da32dfc/psycopg2-binary-2.8.6.tar.gz#sha256=11b9c0ebce097180129e422379b824ae21c8f2a6596b159c7659e2e5a00e1aa0 (from https://pypi.org/simple/psycopg2-binary/) (requires-python:>=2.7,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*). Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

I ran into the same issue with SYSTEM_VERSION_COMPAT=1 pip install psycopg2-binary.

@cheslijones

Pip 21.0.1

Not that I know whether psycopg works on Mac M1 or not. However the words "Make sure to use an up-date-date version of pip" written in the documentation are not there just to waste electrons. With such an old pip version you don't stand a chance.

@cheslijones

Pip 21.0.1

Not that I know whether psycopg works on Mac M1 or not. However the words "Make sure to use an up-date-date version of pip" written in the documentation are not there just to waste electrons. With such an old pip version you don't stand a chance.

Pretty sure 21.0.1 is the latest pip version unless I'm reading this wrong:

https://pypi.org/project/pip/

Released January 30, 2021

Pretty sure 21.0.1 is the latest pip version unless I'm reading this wrong:

mmm... you are right, apologies. I thought we were in the 40s by now.

Ok, keep on having fun with your macs.

Actually, figured it out. Haven't worked on a Mac in a while and forgot about the PostgreSQL dependencies that have to be installed before psycopg2-binary. Never have to do this with Linux so forgot about it...

$ brew install postgresql

$ brew link openssl
Warning: Refusing to link macOS provided/shadowed software: openssl@1.1
If you need to have openssl@1.1 first in your PATH, run:
  echo 'export PATH="/opt/homebrew/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc

For compilers to find openssl@1.1 you may need to set:
  export LDFLAGS="-L/opt/homebrew/opt/openssl@1.1/lib"
  export CPPFLAGS="-I/opt/homebrew/opt/openssl@1.1/include"

For pkg-config to find openssl@1.1 you may need to set:
  export PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@1.1/lib/pkgconfig"

Follow the exports that it shows in the message. Then it worked.

Is there anything standard in all these paths that mac os have to change every single time? is there a MR someone can propose against the setup.py to make your life easier?

can confirm @cheslijones's method was successful for me on an M1 Macbook Air.

LDFLAGS="-L/opt/homebrew/opt/openssl@1.1/lib" CPPFLAGS="-I/opt/homebrew/opt/openssl@1.1/include" PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@1.1/lib/pkgconfig" pip install psycopg2-binary

$ LDFLAGS="-L/opt/homebrew/opt/openssl@1.1/lib" CPPFLAGS="-I/opt/homebrew/opt/openssl@1.1/include" PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@1.1/lib/pkgconfig" pip install psycopg2-binary
Collecting psycopg2-binary
  Using cached psycopg2-binary-2.8.6.tar.gz (384 kB)
Building wheels for collected packages: psycopg2-binary
  Building wheel for psycopg2-binary (setup.py) ... done
  Created wheel for psycopg2-binary: filename=psycopg2_binary-2.8.6-cp39-cp39-macosx_11_0_arm64.whl size=137210 sha256=8f65c425b29f41ff85ff2bff51bf787169c8196c7a70809308f89d7e64e4ed22
  Stored in directory: /Users/khuynh/Library/Caches/pip/wheels/21/fa/fd/4d20397b9959492f88bfa4ba6f993d48de49b93001f90bdda3
Successfully built psycopg2-binary
Installing collected packages: psycopg2-binary
Successfully installed psycopg2-binary-2.8.6

It seems the confusion is because brew recommends installing to /usr/local for rosetta and intel and to /opt/homebrew for ARM [1].

[1] https://docs.brew.sh/Installation

  1. install iTerm
  2. run iTerm using Roseta 2
  3. install venv, after in venv:
  4. pip3 install psycopg2-binary
  5. ...
  6. run Django project in iTerm (with Roseta2)

This one works: LDFLAGS="-L/opt/homebrew/opt/openssl@1.1/lib" CPPFLAGS="-I/opt/homebrew/opt/openssl@1.1/include" PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@1.1/lib/pkgconfig" pip install psycopg2-binary

I recommend you to install postgres first.
brew install postgres
pip3 install psycopg2

commented

Hi there,

I found out a way for installing psycopg2 on a ARM architecture : use a conda virtual environment using miniforge3. This is recommended by apple for installing ML package tensorflow (apparently optimised for the new chip). Here is the miniforge repo for installation :
[1] https://github.com/conda-forge/miniforge#miniforge3

Eventually you can create a yml file to remove some ML package that is shipped along conda. I am not sure this solution is optimal but to me it looks much cleaner that exporting flags in a specific location on the file system.

commented

I wrote about how to get around this in the psycopg2 section of a guide for setting up a Django development environment on an M1 machine.

I used Python 3.8 from Homebrew and Postgres 11 from Homebrew, but long story short the solution that worked for me looks something like this:

export LDFLAGS="-L/opt/homebrew/opt/openssl@1.1/lib -L/opt/homebrew/opt/python@3.8/lib -L/opt/homebrew/opt/icu4c/lib"
export CPPFLAGS="-I/opt/homebrew/opt/openssl@1.1/include -I/opt/homebrew/opt/icu4c/include"
export PATH=/opt/homebrew/opt/postgresql@11/bin:$PATH

Hey 👋 I struggled with installing psycopg2 on the new Apple Mac M1. The solution that finally worked for me for installing not only psycopg2, but also other packages (e.g. pandas and numpy) was using Conda (miniforge3). Created a virtual environment with conda, installed these packages that were having some problems with the M1 (such as psycopg2) with conda install psycopg2 and it worked!

Hi, I'm able to install "psycopg2-binary" locally but getting error while installing the same in a virtual environment.
Look at the logs below:

In file included from psycopg/win32_support.c:28:
In file included from ./psycopg/psycopg.h:38:
./psycopg/config.h:82:13: warning: unused function 'Dprintf' [-Wunused-function]
static void Dprintf(const char *fmt, ...) {}
            ^
1 warning generated.
gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch arm64 -arch x86_64 -g -DPSYCOPG_VERSION=2.9.dev0 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=130002
gcc -bundle -undefined dynamic_lookup -arch arm64 -arch x86_64 -g build/temp.macosx-10.9-universal2-3.9/psycopg/adapter_asis.o build/temp.macosx-10.9-universal2-3.9/psycopg/adapter_binary.o build/temp.macosx-10.9-universal2-3.9/psycopg/adapter_datetime.o build/temp.macosx-10.9-universal2-3.9/psycopg/adapter_list.o build/temp.macosx-10.9-universal2-3.9/psycopg/adapter_pboolean.o build/temp.macosx-10.9-universal2-3.9/psycopg/adapter_pdecimal.o build/temp.macosx-10.9-universal2-3.9/psycopg/adapter_pfloat.o build/temp.macosx-10.9-universal2-3.9/psycopg/adapter_pint.o build/temp.macosx-10.9-universal2-3.9/psycopg/adapter_qstring.o build/temp.macosx-10.9-universal2-3.9/psycopg/aix_support.o build/temp.macosx-10.9-universal2-3.9/psycopg/bytes_format.o build/temp.macosx-10.9-universal2-3.9/psycopg/column_type.o build/temp.macosx-10.9-universal2-3.9/psycopg/connection_int.o build/temp.macosx-10.9-universal2-3.9/psycopg/connection_type.o build/temp.macosx-10.9-universal2-3.9/psycopg/conninfo_type.o build/temp.macosx-10.9-universal2-3.9/psycopg/cursor_int.o build/temp.macosx-10.9-universal2-3.9/psycopg/cursor_type.o build/temp.macosx-10.9-universal2-3.9/psycopg/diagnostics_type.o build/temp.macosx-10.9-universal2-3.9/psycopg/error_type.o build/temp.macosx-10.9-universal2-3.9/psycopg/green.o build/temp.macosx-10.9-universal2-3.9/psycopg/libpq_support.o build/temp.macosx-10.9-universal2-3.9/psycopg/lobject_int.o build/temp.macosx-10.9-universal2-3.9/psycopg/lobject_type.o build/temp.macosx-10.9-universal2-3.9/psycopg/microprotocols.o build/temp.macosx-10.9-universal2-3.9/psycopg/microprotocols_proto.o build/temp.macosx-10.9-universal2-3.9/psycopg/notify_type.o build/temp.macosx-10.9-universal2-3.9/psycopg/pqpath.o build/temp.macosx-10.9-universal2-3.9/psycopg/psycopgmodule.o build/temp.macosx-10.9-universal2-3.9/psycopg/replication_connection_type.o build/temp.macosx-10.9-universal2-3.9/psycopg/replication_cursor_type.o build/temp.macosx-10.9-universal2-3.9/psycopg/replication_message_type.o build/temp.macosx-10.9-universal2-3.9/psycopg/solaris_support.o build/temp.macosx-10.9-universal2-3.9/psycopg/typecast.o build/temp.macosx-10.9-universal2-3.9/psycopg/utils.o build/temp.macosx-10.9-universal2-3.9/psycopg/win32_support.o build/temp.macosx-10.9-universal2-3.9/psycopg/xid_type.o -L/opt/homebrew/lib -lpq -lssl -lcrypto -o build/lib.macosx-10.9-universal2-3.9/psycopg2/_psycopg.cpython-39-darwin.so
ld: library not found for -lssl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: command '/usr/bin/gcc' failed with exit code 1

Using M1 with python3.9
Latest version of pip
exported Postgresql path, LDFlags and CPPFlags.
(BTW only after above steps i was able to install it locally)
But i need to use it within my django project which is in a virtualenv running on same configs.
PS: i'll try to copy psycopg2-binaries from local to virtualenv, maybe that can work out.

@mahi-official
Hi!
I don't know why, but just install pip 21.0.1
After this psycopg2-binary==2.8.6 successfully installed on my mbp 2019
Before I have same error.
There may still be problems with the M1.

Ran into this while running az extension add --name db-up, which installs psycopg2-binary as a dependency in the process. Using the aforementionedexport SYSTEM_VERSION_COMPAT=1 workaround beforehand worked for me.

Note, I'd cross reference with the db-up extension, but I have not idea where that code is hosted.

commented

I recommend you to install postgres first.
brew install postgres
pip3 install psycopg2

It worked on m1 air, thank you sir!

Hi reaching out to fellow macOS users....with an issue I am experiencing when importing psycopg2, i.e. unable to find libq.5.dylib....

I am trying to install psycopg2 2.8.6 on macOS Catalina 10.15.7, running PostgreSQL 10.1. No other postgreSQL database is installed in this environment.

My question is...
Does the build and install of psycopg2 use LIBDIR of pg_config to search for libq library location?

The issue seems to be that no matter how I try to pip install psycopg2 once it has built it seems to look for libpq library at /usr/lib. On this environment libq library is at a different location /Library/PostgreSQL/10/lib.

So....how do I instruct pip install of psycopg2 to search for libqp at /Library/PostgreSQL/10/lib instead of the fixed location of /usr/lib. The answer to that question will likely fix the issue that I am experiencing....

It looks as though the correct libraries are installed, I just need to tell pip install psycopg2 where they are....
How do I achieve this?

$ pg_config

BINDIR = /Library/PostgreSQL/10/bin
DOCDIR = /Library/PostgreSQL/10/doc/postgresql
HTMLDIR = /Library/PostgreSQL/10/doc/postgresql
INCLUDEDIR = /Library/PostgreSQL/10/include
PKGINCLUDEDIR = /Library/PostgreSQL/10/include/postgresql
INCLUDEDIR-SERVER = /Library/PostgreSQL/10/include/postgresql/server
LIBDIR = /Library/PostgreSQL/10/lib
PKGLIBDIR = /Library/PostgreSQL/10/lib/postgresql
LOCALEDIR = /Library/PostgreSQL/10/share/locale
MANDIR = /Library/PostgreSQL/10/share/man
SHAREDIR = /Library/PostgreSQL/10/share/postgresql
SYSCONFDIR = /Library/PostgreSQL/10/etc/postgresql
PGXS = /Library/PostgreSQL/10/lib/postgresql/pgxs/src/makefiles/pgxs.mk
CONFIGURE = '--with-icu' '--prefix=/mnt/hgfs/pginstaller.auto/server/staging_cache/osx.build' '--with-ldap' '--with-openssl' '--with-perl' '--with-python' '--with-tcl' '--with-bonjour' '--with-pam' '--enable-thread-safety' '--with-libxml' '--with-uuid=e2fs' '--with-includes=/opt/local/Current/include/libxml2:/opt/local/Current/include:/opt/local/Current/include/security' '--docdir=/mnt/hgfs/pginstaller.auto/server/staging_cache/osx.build/doc/postgresql' '--with-libxslt' '--with-libedit-preferred' '--with-gssapi' 'CFLAGS=-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -mmacosx-version-min=10.8 -arch i386 -arch x86_64 -O2' 'LDFLAGS=-L/opt/local/Current/lib' 'ICU_CFLAGS=-I/opt/local/Current/include' 'ICU_LIBS=-L/opt/local/Current/lib -licuuc -licudata -licui18n'
CC = gcc
CPPFLAGS = -DFRONTEND -I/opt/local/Current/include -I/opt/local/20151229/include/libxml2 -I/opt/local/Current/include/libxml2 -I/opt/local/Current/include
CFLAGS = -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -mmacosx-version-min=10.8 -arch i386 -arch x86_64 -O2
CFLAGS_SL =
LDFLAGS = -L../../src/common -L/opt/local/Current/lib -L/opt/local/20151229/lib -Wl,-dead_strip_dylibs
LDFLAGS_EX =
LDFLAGS_SL =
LIBS = -lpgcommon -lpgport -lxslt -lxml2 -lpam -lssl -lcrypto -lgssapi_krb5 -lz -ledit -lm
VERSION = PostgreSQL 10.1
python -c "import psycopg2"

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/simon/.pyenv/versions/flaskapp/lib/python3.8/site-packages/psycopg2/__init__.py", line 51, in <module>
    from psycopg2._psycopg import (                     # noqa
ImportError: dlopen(/Users/simon/.pyenv/versions/flaskapp/lib/python3.8/site-packages/psycopg2/_psycopg.cpython-38-darwin.so, 2): Symbol not found: _PQencryptPasswordConn
  Referenced from: /Users/simon/.pyenv/versions/flaskapp/lib/python3.8/site-packages/psycopg2/_psycopg.cpython-38-darwin.so
  Expected in: /usr/lib/libpq.5.dylib
 in /Users/simon/.pyenv/versions/flaskapp/lib/python3.8/site-packages/psycopg2/_psycopg.cpython-38-darwin.so

Think I have managed a workaround....

````sudo install_name_tool -change libpq.5.dylib /Library/PostgreSQL/10/lib/libpq.5.dylib /Users/simon/.pyenv/versions/flaskapp/lib/python3.8/site-packages/psycopg2/_psycopg.cpython-38-darwin.so```

On macOS Catalina install_name_tool can be used to change location of a dynamic library. It used to be that this was done using env vars LD_LIBRARY_CONFIG, DYLD_LIBRARY_PATH or DYLD_FALLBACK_LIBRARY_PATH??? I was setting these and still receiving the same issue....

Now when I do python -c import psycopg2 it is successful......

Not sure if this might help anyone installing and building pyscopg2 on macOS M1 bigSur.....but after doing this it got me up and running....

This method means that if I install psycopg2 in another virtual environment it would have to be updated again to with install_name_tool....not sure if there is a better way?
If I uninstall pscopg2 and then install again in the virtual environment also have to run install_name_tool again!

N.B on doing an ls /usr/lib I see that there is libpq.5.6.dylib* and libpq.5.dylib@. Not sure what is using them but I'm leaving them there untouched!!!!

I managed to install it in MacOS on M1, but what about docker and docker-compose?
ERROR: No matching distribution found for psycopg2-binary==2.8.6

Okay I found workaround. Just use full Python 3 image instead of slim in your Dockerfile!
FROM python:3.9

commented

HEY!
for my ARM M1 Macbook air, the only solution was a combination of:
export CPPFLAGS="-I/opt/homebrew/opt/openssl@1.1/include -I/opt/homebrew/opt/icu4c/include"
export PATH=/opt/homebrew/opt/postgresql@13/bin:$PATH
export LDFLAGS="-L/opt/homebrew/opt/openssl@1.1/lib"
export CPPFLAGS="-I/opt/homebrew/opt/openssl@1.1/include"
export PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@1.1/lib/pkgconfig"

and then, finally:

pip install psycopg2-binary

pfew....

For those who are still struggling to make this work. The following recipe worked for me,
M1 Macbook Pro, Big Sur 11.2.3

Django Cookbook

This one works: LDFLAGS="-L/opt/homebrew/opt/openssl@1.1/lib" CPPFLAGS="-I/opt/homebrew/opt/openssl@1.1/include" PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@1.1/lib/pkgconfig" pip install psycopg2-binary

this solution worked fine for me!

This one works: LDFLAGS="-L/opt/homebrew/opt/openssl@1.1/lib" CPPFLAGS="-I/opt/homebrew/opt/openssl@1.1/include" PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@1.1/lib/pkgconfig" pip install psycopg2-binary

this solution worked fine for me!

worked

please help i have tried everything and tired,
the terminal give me a terrible number of reds

> (venv) dayojohn19@Johns-MacBook-Pro commerce-v4 % brew install postgresql
Warning: postgresql 13.3 is already installed and up-to-date.
To reinstall 13.3, run:

[snip noise]

    ld: warning: directory not found for option '-L/usr/local/opt/openssl/lib'
    ld: warning: directory not found for option '-L/usr/local/opt/openssl/lib/'
    ld: library not found for -lssl
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    error: command '/usr/bin/gcc' failed with exit code 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: '/Volumes/John HDD/heroku/v1/commerce-v4/venv/bin/python' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/gp/nxs7t5js7kb_wfb4qbt3k9l80000gn/T/pip-install-cpdessja/psycopg2_ddfadcdf10414d59a625cee6fc3595bb/setup.py'"'"'; __file__='"'"'/private/var/folders/gp/nxs7t5js7kb_wfb4qbt3k9l80000gn/T/pip-install-cpdessja/psycopg2_ddfadcdf10414d59a625cee6fc3595bb/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/gp/nxs7t5js7kb_wfb4qbt3k9l80000gn/T/pip-record-5x4jvubr/install-record.txt --single-version-externally-managed --compile --install-headers '/Volumes/John HDD/heroku/v1/commerce-v4/venv/include/site/python3.9/psycopg2' Check the logs for full command output.```

my terminal gives me this terrible red lines, when i tried top install psycopg2

Apple M1 with Docker:

If you are having problem with building a Docker image from python:3.9.4-slim or something similar with psycopg2-binary dependency, my work-around was adding apt-get install libpq-dev postgresql.

I was also able to build without just python:3.9.4, suggested by @matacoder. However, I chose to install those other libraries as non-slim version exceeded 1GB in size.

Can you please try to install the current testing packages?

pip install -i https://test.pypi.org/simple psycopg2-binary==2.9.0.dev0

Thank you

@darylyu's solution worked for me

thanks!!

just reiterating from experience
postgres(13) install from homebrew
and make the all the LDFlags are CPPFLAGS are present , in my case one related to openssl were missing

I HAVE TRIED EVERY SOLUTION HERE AND NONE OF THEM WORK. Could someone please help me out? This is urgently blocking new hires from setting up their dev environment

Requirement already satisfied: urllib3==1.26.4 in ./venv/lib/python3.9/site-packages (from -r requirements.txt (line 66)) (1.26.4)
Requirement already satisfied: setuptools>=3.0 in ./venv/lib/python3.9/site-packages (from gunicorn==20.0.4->-r requirements.txt (line 29)) (56.0.0)
Using legacy 'setup.py install' for awslambdaric, since package 'wheel' is not installed.
Using legacy 'setup.py install' for django-allauth, since package 'wheel' is not installed.
Using legacy 'setup.py install' for django-referrer-policy, since package 'wheel' is not installed.
Using legacy 'setup.py install' for django-rest-auth, since package 'wheel' is not installed.
Using legacy 'setup.py install' for psycopg2, since package 'wheel' is not installed.
Installing collected packages: psycopg2-binary, psycopg2, Pint, pandas, mailchimp-transactional, haversine, gunicorn, emoji, django-rest-auth, django-reset-migrations, django-referrer-policy, django-mathfilters, django-graphql-geojson, django-filter, django-extensions, django-cors-headers, django-allauth, dj-database-url, dataclasses-json, boto3, awslambdaric
  Attempting uninstall: psycopg2-binary
    Found existing installation: psycopg2-binary 2.9.dev0
    Uninstalling psycopg2-binary-2.9.dev0:
      Successfully uninstalled psycopg2-binary-2.9.dev0
    Running setup.py install for psycopg2 ... error
    ERROR: Command errored out with exit status 1:
     command: /Users/winston/flueth/venv/bin/python3 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/9_/v8rvqc2j28198mwdq3p4pwbr0000gn/T/pip-install-rf9g4z73/psycopg2_20919a512c624349b4d62dcfda4cdba3/setup.py'"'"'; __file__='"'"'/private/var/folders/9_/v8rvqc2j28198mwdq3p4pwbr0000gn/T/pip-install-rf9g4z73/psycopg2_20919a512c624349b4d62dcfda4cdba3/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/9_/v8rvqc2j28198mwdq3p4pwbr0000gn/T/pip-record-mr7buvkg/install-record.txt --single-version-externally-managed --compile --install-headers /Users/winston/flueth/venv/include/site/python3.9/psycopg2
         cwd: /private/var/folders/9_/v8rvqc2j28198mwdq3p4pwbr0000gn/T/pip-install-rf9g4z73/psycopg2_20919a512c624349b4d62dcfda4cdba3/
    Complete output (151 lines):
    running install
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.9-universal2-3.9
    creating build/lib.macosx-10.9-universal2-3.9/psycopg2
    copying lib/_json.py -> build/lib.macosx-10.9-universal2-3.9/psycopg2
    copying lib/extras.py -> build/lib.macosx-10.9-universal2-3.9/psycopg2
    copying lib/compat.py -> build/lib.macosx-10.9-universal2-3.9/psycopg2
    copying lib/errorcodes.py -> build/lib.macosx-10.9-universal2-3.9/psycopg2
    copying lib/tz.py -> build/lib.macosx-10.9-universal2-3.9/psycopg2
    copying lib/_range.py -> build/lib.macosx-10.9-universal2-3.9/psycopg2
    copying lib/_ipaddress.py -> build/lib.macosx-10.9-universal2-3.9/psycopg2
    copying lib/_lru_cache.py -> build/lib.macosx-10.9-universal2-3.9/psycopg2
    copying lib/__init__.py -> build/lib.macosx-10.9-universal2-3.9/psycopg2
    copying lib/extensions.py -> build/lib.macosx-10.9-universal2-3.9/psycopg2
    copying lib/errors.py -> build/lib.macosx-10.9-universal2-3.9/psycopg2
    copying lib/sql.py -> build/lib.macosx-10.9-universal2-3.9/psycopg2
    copying lib/pool.py -> build/lib.macosx-10.9-universal2-3.9/psycopg2
    running build_ext
    building 'psycopg2._psycopg' extension
    creating build/temp.macosx-10.9-universal2-3.9
    creating build/temp.macosx-10.9-universal2-3.9/psycopg
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.6 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=130003 -DHAVE_LO64=1 -I/Users/winston/flueth/venv/include -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -I. -I/usr/local/include -I/usr/local/include/postgresql/server -c psycopg/adapter_asis.c -o build/temp.macosx-10.9-universal2-3.9/psycopg/adapter_asis.o
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.6 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=130003 -DHAVE_LO64=1 -I/Users/winston/flueth/venv/include -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -I. -I/usr/local/include -I/usr/local/include/postgresql/server -c psycopg/adapter_binary.c -o build/temp.macosx-10.9-universal2-3.9/psycopg/adapter_binary.o
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.6 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=130003 -DHAVE_LO64=1 -I/Users/winston/flueth/venv/include -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -I. -I/usr/local/include -I/usr/local/include/postgresql/server -c psycopg/adapter_datetime.c -o build/temp.macosx-10.9-universal2-3.9/psycopg/adapter_datetime.o
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.6 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=130003 -DHAVE_LO64=1 -I/Users/winston/flueth/venv/include -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -I. -I/usr/local/include -I/usr/local/include/postgresql/server -c psycopg/adapter_list.c -o build/temp.macosx-10.9-universal2-3.9/psycopg/adapter_list.o
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.6 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=130003 -DHAVE_LO64=1 -I/Users/winston/flueth/venv/include -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -I. -I/usr/local/include -I/usr/local/include/postgresql/server -c psycopg/adapter_pboolean.c -o build/temp.macosx-10.9-universal2-3.9/psycopg/adapter_pboolean.o
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.6 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=130003 -DHAVE_LO64=1 -I/Users/winston/flueth/venv/include -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -I. -I/usr/local/include -I/usr/local/include/postgresql/server -c psycopg/adapter_pdecimal.c -o build/temp.macosx-10.9-universal2-3.9/psycopg/adapter_pdecimal.o
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.6 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=130003 -DHAVE_LO64=1 -I/Users/winston/flueth/venv/include -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -I. -I/usr/local/include -I/usr/local/include/postgresql/server -c psycopg/adapter_pfloat.c -o build/temp.macosx-10.9-universal2-3.9/psycopg/adapter_pfloat.o
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.6 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=130003 -DHAVE_LO64=1 -I/Users/winston/flueth/venv/include -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -I. -I/usr/local/include -I/usr/local/include/postgresql/server -c psycopg/adapter_pint.c -o build/temp.macosx-10.9-universal2-3.9/psycopg/adapter_pint.o
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.6 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=130003 -DHAVE_LO64=1 -I/Users/winston/flueth/venv/include -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -I. -I/usr/local/include -I/usr/local/include/postgresql/server -c psycopg/adapter_qstring.c -o build/temp.macosx-10.9-universal2-3.9/psycopg/adapter_qstring.o
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.6 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=130003 -DHAVE_LO64=1 -I/Users/winston/flueth/venv/include -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -I. -I/usr/local/include -I/usr/local/include/postgresql/server -c psycopg/aix_support.c -o build/temp.macosx-10.9-universal2-3.9/psycopg/aix_support.o
    In file included from psycopg/aix_support.c:29:
    In file included from ./psycopg/psycopg.h:38:
    ./psycopg/config.h:82:13: warning: unused function 'Dprintf' [-Wunused-function]
    static void Dprintf(const char *fmt, ...) {}
                ^
    1 warning generated.
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.6 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=130003 -DHAVE_LO64=1 -I/Users/winston/flueth/venv/include -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -I. -I/usr/local/include -I/usr/local/include/postgresql/server -c psycopg/bytes_format.c -o build/temp.macosx-10.9-universal2-3.9/psycopg/bytes_format.o
    In file included from psycopg/bytes_format.c:82:
    In file included from ./psycopg/psycopg.h:38:
    ./psycopg/config.h:82:13: warning: unused function 'Dprintf' [-Wunused-function]
    static void Dprintf(const char *fmt, ...) {}
                ^
    1 warning generated.
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.6 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=130003 -DHAVE_LO64=1 -I/Users/winston/flueth/venv/include -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -I. -I/usr/local/include -I/usr/local/include/postgresql/server -c psycopg/column_type.c -o build/temp.macosx-10.9-universal2-3.9/psycopg/column_type.o
    In file included from psycopg/column_type.c:28:
    In file included from ./psycopg/psycopg.h:38:
    ./psycopg/config.h:82:13: warning: unused function 'Dprintf' [-Wunused-function]
    static void Dprintf(const char *fmt, ...) {}
                ^
    1 warning generated.
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.6 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=130003 -DHAVE_LO64=1 -I/Users/winston/flueth/venv/include -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -I. -I/usr/local/include -I/usr/local/include/postgresql/server -c psycopg/connection_int.c -o build/temp.macosx-10.9-universal2-3.9/psycopg/connection_int.o
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.6 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=130003 -DHAVE_LO64=1 -I/Users/winston/flueth/venv/include -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -I. -I/usr/local/include -I/usr/local/include/postgresql/server -c psycopg/connection_type.c -o build/temp.macosx-10.9-universal2-3.9/psycopg/connection_type.o
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.6 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=130003 -DHAVE_LO64=1 -I/Users/winston/flueth/venv/include -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -I. -I/usr/local/include -I/usr/local/include/postgresql/server -c psycopg/conninfo_type.c -o build/temp.macosx-10.9-universal2-3.9/psycopg/conninfo_type.o
    In file included from psycopg/conninfo_type.c:28:
    In file included from ./psycopg/psycopg.h:38:
    ./psycopg/config.h:82:13: warning: unused function 'Dprintf' [-Wunused-function]
    static void Dprintf(const char *fmt, ...) {}
                ^
    1 warning generated.
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.6 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=130003 -DHAVE_LO64=1 -I/Users/winston/flueth/venv/include -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -I. -I/usr/local/include -I/usr/local/include/postgresql/server -c psycopg/cursor_int.c -o build/temp.macosx-10.9-universal2-3.9/psycopg/cursor_int.o
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.6 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=130003 -DHAVE_LO64=1 -I/Users/winston/flueth/venv/include -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -I. -I/usr/local/include -I/usr/local/include/postgresql/server -c psycopg/cursor_type.c -o build/temp.macosx-10.9-universal2-3.9/psycopg/cursor_type.o
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.6 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=130003 -DHAVE_LO64=1 -I/Users/winston/flueth/venv/include -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -I. -I/usr/local/include -I/usr/local/include/postgresql/server -c psycopg/diagnostics_type.c -o build/temp.macosx-10.9-universal2-3.9/psycopg/diagnostics_type.o
    In file included from psycopg/diagnostics_type.c:28:
    In file included from ./psycopg/psycopg.h:38:
    ./psycopg/config.h:82:13: warning: unused function 'Dprintf' [-Wunused-function]
    static void Dprintf(const char *fmt, ...) {}
                ^
    1 warning generated.
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.6 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=130003 -DHAVE_LO64=1 -I/Users/winston/flueth/venv/include -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -I. -I/usr/local/include -I/usr/local/include/postgresql/server -c psycopg/error_type.c -o build/temp.macosx-10.9-universal2-3.9/psycopg/error_type.o
    In file included from psycopg/error_type.c:28:
    In file included from ./psycopg/psycopg.h:38:
    ./psycopg/config.h:82:13: warning: unused function 'Dprintf' [-Wunused-function]
    static void Dprintf(const char *fmt, ...) {}
                ^
    1 warning generated.
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.6 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=130003 -DHAVE_LO64=1 -I/Users/winston/flueth/venv/include -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -I. -I/usr/local/include -I/usr/local/include/postgresql/server -c psycopg/green.c -o build/temp.macosx-10.9-universal2-3.9/psycopg/green.o
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.6 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=130003 -DHAVE_LO64=1 -I/Users/winston/flueth/venv/include -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -I. -I/usr/local/include -I/usr/local/include/postgresql/server -c psycopg/libpq_support.c -o build/temp.macosx-10.9-universal2-3.9/psycopg/libpq_support.o
    In file included from psycopg/libpq_support.c:30:
    In file included from ./psycopg/psycopg.h:38:
    ./psycopg/config.h:82:13: warning: unused function 'Dprintf' [-Wunused-function]
    static void Dprintf(const char *fmt, ...) {}
                ^
    1 warning generated.
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.6 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=130003 -DHAVE_LO64=1 -I/Users/winston/flueth/venv/include -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -I. -I/usr/local/include -I/usr/local/include/postgresql/server -c psycopg/lobject_int.c -o build/temp.macosx-10.9-universal2-3.9/psycopg/lobject_int.o
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.6 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=130003 -DHAVE_LO64=1 -I/Users/winston/flueth/venv/include -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -I. -I/usr/local/include -I/usr/local/include/postgresql/server -c psycopg/lobject_type.c -o build/temp.macosx-10.9-universal2-3.9/psycopg/lobject_type.o
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.6 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=130003 -DHAVE_LO64=1 -I/Users/winston/flueth/venv/include -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -I. -I/usr/local/include -I/usr/local/include/postgresql/server -c psycopg/microprotocols.c -o build/temp.macosx-10.9-universal2-3.9/psycopg/microprotocols.o
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.6 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=130003 -DHAVE_LO64=1 -I/Users/winston/flueth/venv/include -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -I. -I/usr/local/include -I/usr/local/include/postgresql/server -c psycopg/microprotocols_proto.c -o build/temp.macosx-10.9-universal2-3.9/psycopg/microprotocols_proto.o
    In file included from psycopg/microprotocols_proto.c:28:
    In file included from ./psycopg/psycopg.h:38:
    ./psycopg/config.h:82:13: warning: unused function 'Dprintf' [-Wunused-function]
    static void Dprintf(const char *fmt, ...) {}
                ^
    1 warning generated.
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.6 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=130003 -DHAVE_LO64=1 -I/Users/winston/flueth/venv/include -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -I. -I/usr/local/include -I/usr/local/include/postgresql/server -c psycopg/notify_type.c -o build/temp.macosx-10.9-universal2-3.9/psycopg/notify_type.o
    In file included from psycopg/notify_type.c:28:
    In file included from ./psycopg/psycopg.h:38:
    ./psycopg/config.h:82:13: warning: unused function 'Dprintf' [-Wunused-function]
    static void Dprintf(const char *fmt, ...) {}
                ^
    1 warning generated.
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.6 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=130003 -DHAVE_LO64=1 -I/Users/winston/flueth/venv/include -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -I. -I/usr/local/include -I/usr/local/include/postgresql/server -c psycopg/pqpath.c -o build/temp.macosx-10.9-universal2-3.9/psycopg/pqpath.o
    psycopg/pqpath.c:138:17: warning: implicit conversion from enumeration type 'ConnStatusType' to different enumeration type 'ExecStatusType' [-Wenum-conversion]
                    PQstatus(conn->pgconn) : PQresultStatus(*pgres)));
                    ^~~~~~~~~~~~~~~~~~~~~~
    psycopg/pqpath.c:1717:11: warning: code will never be executed [-Wunreachable-code]
        ret = 1;
              ^
    psycopg/pqpath.c:1822:17: warning: implicit conversion from enumeration type 'ConnStatusType' to different enumeration type 'ExecStatusType' [-Wenum-conversion]
                    PQstatus(curs->conn->pgconn) : PQresultStatus(curs->pgres)));
                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
    3 warnings generated.
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.6 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=130003 -DHAVE_LO64=1 -I/Users/winston/flueth/venv/include -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -I. -I/usr/local/include -I/usr/local/include/postgresql/server -c psycopg/psycopgmodule.c -o build/temp.macosx-10.9-universal2-3.9/psycopg/psycopgmodule.o
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.6 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=130003 -DHAVE_LO64=1 -I/Users/winston/flueth/venv/include -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -I. -I/usr/local/include -I/usr/local/include/postgresql/server -c psycopg/replication_connection_type.c -o build/temp.macosx-10.9-universal2-3.9/psycopg/replication_connection_type.o
    In file included from psycopg/replication_connection_type.c:28:
    In file included from ./psycopg/psycopg.h:38:
    ./psycopg/config.h:82:13: warning: unused function 'Dprintf' [-Wunused-function]
    static void Dprintf(const char *fmt, ...) {}
                ^
    1 warning generated.
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.6 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=130003 -DHAVE_LO64=1 -I/Users/winston/flueth/venv/include -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -I. -I/usr/local/include -I/usr/local/include/postgresql/server -c psycopg/replication_cursor_type.c -o build/temp.macosx-10.9-universal2-3.9/psycopg/replication_cursor_type.o
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.6 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=130003 -DHAVE_LO64=1 -I/Users/winston/flueth/venv/include -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -I. -I/usr/local/include -I/usr/local/include/postgresql/server -c psycopg/replication_message_type.c -o build/temp.macosx-10.9-universal2-3.9/psycopg/replication_message_type.o
    In file included from psycopg/replication_message_type.c:28:
    In file included from ./psycopg/psycopg.h:38:
    ./psycopg/config.h:82:13: warning: unused function 'Dprintf' [-Wunused-function]
    static void Dprintf(const char *fmt, ...) {}
                ^
    1 warning generated.
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.6 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=130003 -DHAVE_LO64=1 -I/Users/winston/flueth/venv/include -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -I. -I/usr/local/include -I/usr/local/include/postgresql/server -c psycopg/solaris_support.c -o build/temp.macosx-10.9-universal2-3.9/psycopg/solaris_support.o
    In file included from psycopg/solaris_support.c:29:
    In file included from ./psycopg/psycopg.h:38:
    ./psycopg/config.h:82:13: warning: unused function 'Dprintf' [-Wunused-function]
    static void Dprintf(const char *fmt, ...) {}
                ^
    1 warning generated.
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.6 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=130003 -DHAVE_LO64=1 -I/Users/winston/flueth/venv/include -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -I. -I/usr/local/include -I/usr/local/include/postgresql/server -c psycopg/typecast.c -o build/temp.macosx-10.9-universal2-3.9/psycopg/typecast.o
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.6 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=130003 -DHAVE_LO64=1 -I/Users/winston/flueth/venv/include -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -I. -I/usr/local/include -I/usr/local/include/postgresql/server -c psycopg/utils.c -o build/temp.macosx-10.9-universal2-3.9/psycopg/utils.o
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.6 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=130003 -DHAVE_LO64=1 -I/Users/winston/flueth/venv/include -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -I. -I/usr/local/include -I/usr/local/include/postgresql/server -c psycopg/win32_support.c -o build/temp.macosx-10.9-universal2-3.9/psycopg/win32_support.o
    In file included from psycopg/win32_support.c:28:
    In file included from ./psycopg/psycopg.h:38:
    ./psycopg/config.h:82:13: warning: unused function 'Dprintf' [-Wunused-function]
    static void Dprintf(const char *fmt, ...) {}
                ^
    1 warning generated.
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -DPSYCOPG_VERSION=2.8.6 (dt dec pq3 ext lo64) -DPG_VERSION_NUM=130003 -DHAVE_LO64=1 -I/Users/winston/flueth/venv/include -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -I. -I/usr/local/include -I/usr/local/include/postgresql/server -c psycopg/xid_type.c -o build/temp.macosx-10.9-universal2-3.9/psycopg/xid_type.o
    gcc -bundle -undefined dynamic_lookup -arch x86_64 -g build/temp.macosx-10.9-universal2-3.9/psycopg/adapter_asis.o build/temp.macosx-10.9-universal2-3.9/psycopg/adapter_binary.o build/temp.macosx-10.9-universal2-3.9/psycopg/adapter_datetime.o build/temp.macosx-10.9-universal2-3.9/psycopg/adapter_list.o build/temp.macosx-10.9-universal2-3.9/psycopg/adapter_pboolean.o build/temp.macosx-10.9-universal2-3.9/psycopg/adapter_pdecimal.o build/temp.macosx-10.9-universal2-3.9/psycopg/adapter_pfloat.o build/temp.macosx-10.9-universal2-3.9/psycopg/adapter_pint.o build/temp.macosx-10.9-universal2-3.9/psycopg/adapter_qstring.o build/temp.macosx-10.9-universal2-3.9/psycopg/aix_support.o build/temp.macosx-10.9-universal2-3.9/psycopg/bytes_format.o build/temp.macosx-10.9-universal2-3.9/psycopg/column_type.o build/temp.macosx-10.9-universal2-3.9/psycopg/connection_int.o build/temp.macosx-10.9-universal2-3.9/psycopg/connection_type.o build/temp.macosx-10.9-universal2-3.9/psycopg/conninfo_type.o build/temp.macosx-10.9-universal2-3.9/psycopg/cursor_int.o build/temp.macosx-10.9-universal2-3.9/psycopg/cursor_type.o build/temp.macosx-10.9-universal2-3.9/psycopg/diagnostics_type.o build/temp.macosx-10.9-universal2-3.9/psycopg/error_type.o build/temp.macosx-10.9-universal2-3.9/psycopg/green.o build/temp.macosx-10.9-universal2-3.9/psycopg/libpq_support.o build/temp.macosx-10.9-universal2-3.9/psycopg/lobject_int.o build/temp.macosx-10.9-universal2-3.9/psycopg/lobject_type.o build/temp.macosx-10.9-universal2-3.9/psycopg/microprotocols.o build/temp.macosx-10.9-universal2-3.9/psycopg/microprotocols_proto.o build/temp.macosx-10.9-universal2-3.9/psycopg/notify_type.o build/temp.macosx-10.9-universal2-3.9/psycopg/pqpath.o build/temp.macosx-10.9-universal2-3.9/psycopg/psycopgmodule.o build/temp.macosx-10.9-universal2-3.9/psycopg/replication_connection_type.o build/temp.macosx-10.9-universal2-3.9/psycopg/replication_cursor_type.o build/temp.macosx-10.9-universal2-3.9/psycopg/replication_message_type.o build/temp.macosx-10.9-universal2-3.9/psycopg/solaris_support.o build/temp.macosx-10.9-universal2-3.9/psycopg/typecast.o build/temp.macosx-10.9-universal2-3.9/psycopg/utils.o build/temp.macosx-10.9-universal2-3.9/psycopg/win32_support.o build/temp.macosx-10.9-universal2-3.9/psycopg/xid_type.o -L/usr/local/lib -lpq -lssl -lcrypto -o build/lib.macosx-10.9-universal2-3.9/psycopg2/_psycopg.cpython-39-darwin.so
    ld: library not found for -lssl
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    error: command '/usr/bin/gcc' failed with exit code 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /Users/winston/flueth/venv/bin/python3 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/9_/v8rvqc2j28198mwdq3p4pwbr0000gn/T/pip-install-rf9g4z73/psycopg2_20919a512c624349b4d62dcfda4cdba3/setup.py'"'"'; __file__='"'"'/private/var/folders/9_/v8rvqc2j28198mwdq3p4pwbr0000gn/T/pip-install-rf9g4z73/psycopg2_20919a512c624349b4d62dcfda4cdba3/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/9_/v8rvqc2j28198mwdq3p4pwbr0000gn/T/pip-record-mr7buvkg/install-record.txt --single-version-externally-managed --compile --install-headers /Users/winston/flueth/venv/include/site/python3.9/psycopg2 Check the logs for full command output.

@opqpop thank you for the uppercase.

Can you try pip install -i https://test.pypi.org/simple psycopg2-binary==2.9.0.dev0? Thank you.

@dvarrazzo it worked! I got the same error as @opqpop mentioned.

@dvarrazzo Is there any permanent solution?

@meistiyak I will release 2.9 with the fix in a few days.

Actually, figured it out. Haven't worked on a Mac in a while and forgot about the PostgreSQL dependencies that have to be installed before psycopg2-binary. Never have to do this with Linux so forgot about it...

$ brew install postgresql

$ brew link openssl
Warning: Refusing to link macOS provided/shadowed software: openssl@1.1
If you need to have openssl@1.1 first in your PATH, run:
  echo 'export PATH="/opt/homebrew/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc

For compilers to find openssl@1.1 you may need to set:
  export LDFLAGS="-L/opt/homebrew/opt/openssl@1.1/lib"
  export CPPFLAGS="-I/opt/homebrew/opt/openssl@1.1/include"

For pkg-config to find openssl@1.1 you may need to set:
  export PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@1.1/lib/pkgconfig"

Follow the exports that it shows in the message. Then it worked.

This worked for me 😷

@dvarrazzo it worked! I got the same error as @opqpop mentioned.

ditto. I had the same error -- installing psycopg2-binary==2.9.0.dev0 fixed it. I'm on Big Sur with M1 chip.

En realidad, lo descubrí. No he trabajado en una Mac por un tiempo y me olvidé de las dependencias de PostgreSQL que deben instalarse antes psycopg2-binary. Nunca tengo que hacer esto con Linux, así que olvídalo ...

$ brew install postgresql

$ brew link openssl
Warning: Refusing to link macOS provided/shadowed software: openssl@1.1
If you need to have openssl@1.1 first in your PATH, run:
  echo 'export PATH="/opt/homebrew/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc

For compilers to find openssl@1.1 you may need to set:
  export LDFLAGS="-L/opt/homebrew/opt/openssl@1.1/lib"
  export CPPFLAGS="-I/opt/homebrew/opt/openssl@1.1/include"

For pkg-config to find openssl@1.1 you may need to set:
  export PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@1.1/lib/pkgconfig"

Siga lo exportsque se muestra en el mensaje. Entonces funcionó.

MAC, M1 (Big Sur on Apple silicon), me falto instalar los complementos de "postgresql", funciona

commented

@meistiyak I will release 2.9 with the fix in a few days.

Any luck with that update? Tried all of the above and not working for me. I have lots of nice new packages though.

Psycopg 2.9 has been released, which should solve the build problem with Mac OS.

The binary packages are not compatible with the Apple M1 in ARM mode, but building should be fixed. See #1286 for M1 support.

Actually, figured it out. Haven't worked on a Mac in a while and forgot about the PostgreSQL dependencies that have to be installed before psycopg2-binary. Never have to do this with Linux so forgot about it...

$ brew install postgresql

$ brew link openssl
Warning: Refusing to link macOS provided/shadowed software: openssl@1.1
If you need to have openssl@1.1 first in your PATH, run:
  echo 'export PATH="/opt/homebrew/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc

For compilers to find openssl@1.1 you may need to set:
  export LDFLAGS="-L/opt/homebrew/opt/openssl@1.1/lib"
  export CPPFLAGS="-I/opt/homebrew/opt/openssl@1.1/include"

For pkg-config to find openssl@1.1 you may need to set:
  export PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@1.1/lib/pkgconfig"

Follow the exports that it shows in the message. Then it worked.

You are great bro... was getting frustrated over this. Thanks a lot

What worked for me on Mac:

$ brew install postgresql

$ brew link openssl
Warning: Refusing to link macOS provided/shadowed software: openssl@1.1
If you need to have openssl@1.1 first in your PATH, run:
echo 'export PATH="/opt/homebrew/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc

For compilers to find openssl@1.1 you may need to set:
export LDFLAGS="-L/opt/homebrew/opt/openssl@1.1/lib"
export CPPFLAGS="-I/opt/homebrew/opt/openssl@1.1/include"

For pkg-config to find openssl@1.1 you may need to set:
export PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@1.1/lib/pkgconfig"

Then I downloaded and installed PG Admin from https://www.pgadmin.org/download/
Then my system will be able to resolve the psycopg2 requirements and "pip install psycopg2-binary" worked just fine.

This issue still persists

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/django/db/backends/postgresql/base.py", line 25, in <module>
    import psycopg2 as Database
ModuleNotFoundError: No module named 'psycopg2'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/code/manage.py", line 22, in <module>
    main()
  File "/code/manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 395, in execute
    django.setup()
  File "/usr/local/lib/python3.9/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/lib/python3.9/site-packages/django/apps/registry.py", line 114, in populate
    app_config.import_models()
  File "/usr/local/lib/python3.9/site-packages/django/apps/config.py", line 301, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 855, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/usr/local/lib/python3.9/site-packages/django/contrib/auth/models.py", line 3, in <module>
    from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
  File "/usr/local/lib/python3.9/site-packages/django/contrib/auth/base_user.py", line 48, in <module>
    class AbstractBaseUser(models.Model):
  File "/usr/local/lib/python3.9/site-packages/django/db/models/base.py", line 122, in __new__
    new_class.add_to_class('_meta', Options(meta, app_label))
  File "/usr/local/lib/python3.9/site-packages/django/db/models/base.py", line 326, in add_to_class
    value.contribute_to_class(cls, name)
  File "/usr/local/lib/python3.9/site-packages/django/db/models/options.py", line 207, in contribute_to_class
    self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
  File "/usr/local/lib/python3.9/site-packages/django/utils/connection.py", line 15, in __getattr__
    return getattr(self._connections[self._alias], item)
  File "/usr/local/lib/python3.9/site-packages/django/utils/connection.py", line 62, in __getitem__
    conn = self.create_connection(alias)
  File "/usr/local/lib/python3.9/site-packages/django/db/utils.py", line 204, in create_connection
    backend = load_backend(db['ENGINE'])
  File "/usr/local/lib/python3.9/site-packages/django/db/utils.py", line 111, in load_backend
    return import_module('%s.base' % backend_name)
  File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "/usr/local/lib/python3.9/site-packages/django/db/backends/postgresql/base.py", line 29, in <module>
    raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: No module named 'psycopg2'
ERROR: 1

pip install --upgrade wheel
pip install --upgrade setuptools
pip install psycopg2

I am using Mac os big sure and this works for me.
install openssl using brew
brew install openssl
after that export these variables in the terminal.

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

then finally install psycopg2
pip3 install psycopg2

Hi @Nkarnaud , I am using Big Sur on Apple silicon. This doesn't work for me. Can you help? :(

Thanks, it worked for me

I am using macOS Big Sur 11.5.2 and this worked for me

brew install openssl

(which installed openssl@1.1 1.1.1l)

export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"
python3.9 -m pip install -U pip setuptools wheel
python3.9 -m pip install psycopg2-binary

Successfully installed psycopg2-binary-2.9.1

@thebogdan out of curiosity:

  • does the above work if you install psycopg instead of psycopg-binary?
  • does the above work if you don't specify the env vars?

thank you

@thebogdan out of curiosity:

  • does the above work if you install psycopg instead of psycopg-binary?
  • does the above work if you don't specify the env vars?

thank you

nope. unfortunately not.

Here's what worked for me:

  • update Python to 3.9.7 (⚠️ make sure to download the python-3.9.7-macos11.pkg from python.org - the other one is for Intel based Macs)
  • brew install postgresql
  • optional: create a venv (python3 -m venv myvenv)
  • pip install psycopg2-binary --force-reinstall --no-cache-dir

check

❯ pip list
Package         Version
--------------- -------
pip             21.2.4
psycopg2-binary 2.9.1
setuptools      57.4.0

This problem may be from not installed postgre (I use postgre from docker), cause install postgre
brew install postgresql
And, after this (postgre is off default), try install psycopg2. It's help to me (Mac mini m1)

A lot of answers, suggest installing postgresql, It's the whole PostgreSQL Package, what's the point of installing psycopg2-binary if we are going to install postgresql on the system?

Anyway, My solution was to install libpq instead of postgresql, it contains only the C Library API which is required to build the psycopg2-binary.

$ brew install libpq

add the libpq binaries path to your $PATH, I have a MacBook Pro M1 and I use ZSH, may be a bit different for other Macbooks and Shells.

$ echo 'export PATH="/opt/homebrew/opt/libpq/bin:$PATH"' >> ~/.zshrc

Restart your Terminal (or reload shell) and install the package

$ pip3 install psycopg2-binary --force-reinstall --no-cache-dir

@DarkSuniuM I haven't try yet but I guess it's safe to uninstall postgresql after psycopg2-binary was successfully installed(?)

@DarkSuniuM I haven't try yet but I guess it's safe to uninstall postgresql after psycopg2-binary was successfully installed(?)

Yes, it is, but if you have multiple projects inside of multiple virtual envs, then you wanna keep it installed for the sake of next projects,

Also, as you read in my response, you can replace it with libpq

A lot of answers, suggest installing postgresql, It's the whole PostgreSQL Package, what's the point of installing psycopg2-binary if we are going to install postgresql on the system?

Anyway, My solution was to install libpq instead of postgresql, it contains only the C Library API which is required to build the psycopg2-binary.

$ brew install libpq

add the libpq binaries path to your $PATH, I have a MacBook Pro M1 and I use ZSH, may be a bit different for other Macbooks and Shells.

$ echo 'export PATH="/opt/homebrew/opt/libpq/bin:$PATH"' >> ~/.zshrc

Restart your Terminal (or reload shell) and install the package

$ pip3 install psycopg2-binary --force-reinstall --no-cache-dir

The idea to use libqp is a lot better than using postgres, but you will need to install openssl too

brew install openssl

and set the path for the same as mentioned in above comments, which in my case had a different path compared to what is mentioned above.

export LDFLAGS="-L/opt/homebrew/opt/openssl@3/lib"
export CPPFLAGS="-I/opt/homebrew/opt/openssl@3/include"

After this I am able to use both psycopg2 as well as psycopg2-binary

commented

This library has caused me so much pain and suffering.

I recommend you to install postgres first. brew install postgres pip3 install psycopg2

This worked for me
Apple M1 Pro Macbook
Monterey 12.0.1