Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot install psycopg2 with pip3 on M1 Mac

I cannot install psycopg2 on my M1 Mac and I used pip3.

When I tried to install with pip3 install psycopg2 The output like that:

  ERROR: Command errored out with exit status 1:
     command: /opt/homebrew/opt/[email protected]/bin/python3.9 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/m5/vhnyyjg16gd352x6wdhpjysh0000gn/T/pip-install-9wiqe2nr/psycopg2_147a5ae8fd5a47079480274f4225edbf/setup.py'"'"'; __file__='"'"'/private/var/folders/m5/vhnyyjg16gd352x6wdhpjysh0000gn/T/pip-install-9wiqe2nr/psycopg2_147a5ae8fd5a47079480274f4225edbf/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/m5/vhnyyjg16gd352x6wdhpjysh0000gn/T/pip-pip-egg-info-06hnnl2t
         cwd: /private/var/folders/m5/vhnyyjg16gd352x6wdhpjysh0000gn/T/pip-install-9wiqe2nr/psycopg2_147a5ae8fd5a47079480274f4225edbf/
    Complete output (23 lines):
    running egg_info
    creating /private/var/folders/m5/vhnyyjg16gd352x6wdhpjysh0000gn/T/pip-pip-egg-info-06hnnl2t/psycopg2.egg-info
    writing /private/var/folders/m5/vhnyyjg16gd352x6wdhpjysh0000gn/T/pip-pip-egg-info-06hnnl2t/psycopg2.egg-info/PKG-INFO
    writing dependency_links to /private/var/folders/m5/vhnyyjg16gd352x6wdhpjysh0000gn/T/pip-pip-egg-info-06hnnl2t/psycopg2.egg-info/dependency_links.txt
    writing top-level names to /private/var/folders/m5/vhnyyjg16gd352x6wdhpjysh0000gn/T/pip-pip-egg-info-06hnnl2t/psycopg2.egg-info/top_level.txt
    writing manifest file '/private/var/folders/m5/vhnyyjg16gd352x6wdhpjysh0000gn/T/pip-pip-egg-info-06hnnl2t/psycopg2.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/fd/ae/98cb7a0cbb1d748ee547b058b14604bd0e9bf285a8e0cc5d148f8a8a952e/psycopg2-2.8.6.tar.gz#sha256=fb23f6c71107c37fd667cb4ea363ddeb936b348bbd6449278eb92c189699f543 (from https://pypi.org/simple/psycopg2/) (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.
  Using cached psycopg2-2.8.5.tar.gz (380 kB)
    ERROR: Command errored out with exit status 1:
     command: /opt/homebrew/opt/[email protected]/bin/python3.9 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/m5/vhnyyjg16gd352x6wdhpjysh0000gn/T/pip-install-9wiqe2nr/psycopg2_97efcf6747c249769acdc8430ba4238f/setup.py'"'"'; __file__='"'"'/private/var/folders/m5/vhnyyjg16gd352x6wdhpjysh0000gn/T/pip-install-9wiqe2nr/psycopg2_97efcf6747c249769acdc8430ba4238f/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/m5/vhnyyjg16gd352x6wdhpjysh0000gn/T/pip-pip-egg-info-ap2am61r
         cwd: /private/var/folders/m5/vhnyyjg16gd352x6wdhpjysh0000gn/T/pip-install-9wiqe2nr/psycopg2_97efcf6747c249769acdc8430ba4238f/
    Complete output (23 lines):
    running egg_info
    creating /private/var/folders/m5/vhnyyjg16gd352x6wdhpjysh0000gn/T/pip-pip-egg-info-ap2am61r/psycopg2.egg-info
    writing /private/var/folders/m5/vhnyyjg16gd352x6wdhpjysh0000gn/T/pip-pip-egg-info-ap2am61r/psycopg2.egg-info/PKG-INFO
    writing dependency_links to /private/var/folders/m5/vhnyyjg16gd352x6wdhpjysh0000gn/T/pip-pip-egg-info-ap2am61r/psycopg2.egg-info/dependency_links.txt
    writing top-level names to /private/var/folders/m5/vhnyyjg16gd352x6wdhpjysh0000gn/T/pip-pip-egg-info-ap2am61r/psycopg2.egg-info/top_level.txt
    writing manifest file '/private/var/folders/m5/vhnyyjg16gd352x6wdhpjysh0000gn/T/pip-pip-egg-info-ap2am61r/psycopg2.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>).
    ==============================================================================
    Its beginning of the error, After that its tried to install each previous version of Psycopg 
    ==============================================================================

Also, I tried to install with source code with :

git clone https://github.com/psycopg/psycopg2.git
cd psycopg2
python3 setup.py build

Its return as error like that:

running build
running build_py
running build_ext

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

Also
python3 setup.py build return the same error as python3 setup.py build

How can I install it?

like image 424
akasaa Avatar asked Mar 31 '21 12:03

akasaa


People also ask

Does psycopg2 work with Python 3?

The current psycopg2 implementation supports: Python 2 versions from 2.6 to 2.7. Python 3 versions from 3.2 to 3.6. PostgreSQL server versions from 7.4 to 9.6.

Could not find a version that satisfies the requirement psycopg2?

Queries related to “could not find a version that satisfies the requirement psycopg2” You may install a binary package by installing 'psycopg2-binary' from PyPI. If you want to install psycopg2 from source, please install the packages required for the build and try again. PyPI 'psycopg2-binary' package instead.

What is the difference between psycopg2 and psycopg2-binary?

psycopg2-binary and psycopg2 both give us the same code that we interact with. The difference between the two is in how that code is installed in our computer.

What happened to pip install psycopg2-binary?

In version 2.7.x, pip install psycopg2 would have tried to install automatically the binary package of Psycopg. Because of concurrency problems binary packages have displayed, psycopg2-binary has become a separate package, and from 2.8 it has become the only way to install the binary package.

What are the prerequisites to install psycopg2?

The current psycopg2 implementation supports: Python versions from 3.6 to 3.10 PostgreSQL server versions from 7.4 to 14 PostgreSQL client library version from 9.1 The build prerequisites are to be met in order to install Psycopg from source code, from a source distribution package, GitHub or from PyPI.

Does psycopg2-binary work on the Apple M1?

The binary packages are not compatible with the Apple M1 in ARM mode, but building should be fixed. See #1286 for M1 support. Sorry, something went wrong. Sorry, something went wrong. 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.

How to install PIP3 on Mac?

Install Pip3 on Mac With the Homebrew Package Manager You can use two primary methods to install pip3 on Mac through Python: the get-pip.py file and the Homebrew package manager. This tutorial will introduce and demonstrate these methods to help you install pip3 on your Mac device. Install Pip3 on Mac With the get-pip.py File


Video Answer


3 Answers

try this:

brew install libpq --build-from-source
brew install openssl

export LDFLAGS="-L/opt/homebrew/opt/[email protected]/lib -L/opt/homebrew/opt/libpq/lib"
export CPPFLAGS="-I/opt/homebrew/opt/[email protected]/include -I/opt/homebrew/opt/libpq/include"

pip3 install psycopg2
like image 159
user2884165 Avatar answered Oct 22 '22 23:10

user2884165


Before reverting to any of the older answers, I would recommend trying the following:

Install Postgres using brew install postgres, then pip3 install psycopg2.

Worked on Mac M1, Monterey, Python 3.9.

Thanks to Kori Vernon.

like image 38
user3661992 Avatar answered Oct 23 '22 00:10

user3661992


Thanks to active development, now there is a new release of psycopg2 as well as psycopg2-binary which is compatible with M1 devices. Ver. 2.9.1 works smooth. Tried and tested Reference - https://github.com/psycopg/psycopg2/issues/1200

like image 6
Shubhank Saxena Avatar answered Oct 23 '22 01:10

Shubhank Saxena