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

Created on 21 Nov 2020  路  6Comments  路  Source: psycopg/psycopg2

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!)

Most helpful comment

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

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

All 6 comments

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.

Was this page helpful?
0 / 5 - 0 ratings