Can not install psycopg2 on Mac 12.3, I keep getting this error
Asked Answered
G

3

10

Ive recently bought a MacBook Pro and was setting it up for some python and Django programming but I ended up having problems installing psycopg2, I've tried several things already and none of those worked for me, here left the error,

Collecting psycopg2
  Using cached psycopg2-2.9.3.tar.gz (380 kB)
  Preparing metadata (setup.py) ... error
  error: subprocess-exited-with-error
  
  × python setup.py egg_info did not run successfully.
  │ exit code: 1
  ╰─> [23 lines of output]
      running egg_info
      creating /private/var/folders/7f/ssr40bmj6t3_yq0cv_43cttc0000gn/T/pip-pip-egg-info-noe7l09b/psycopg2.egg-info
      writing /private/var/folders/7f/ssr40bmj6t3_yq0cv_43cttc0000gn/T/pip-pip-egg-info-noe7l09b/psycopg2.egg-info/PKG-INFO
      writing dependency_links to /private/var/folders/7f/ssr40bmj6t3_yq0cv_43cttc0000gn/T/pip-pip-egg-info-noe7l09b/psycopg2.egg-info/dependency_links.txt
      writing top-level names to /private/var/folders/7f/ssr40bmj6t3_yq0cv_43cttc0000gn/T/pip-pip-egg-info-noe7l09b/psycopg2.egg-info/top_level.txt
      writing manifest file '/private/var/folders/7f/ssr40bmj6t3_yq0cv_43cttc0000gn/T/pip-pip-egg-info-noe7l09b/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>).
      
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed

× Encountered error while generating package metadata.
╰─> See above for output.

note: This is an issue with the package mentioned above, not pip.
hint: See above for details.

It shows it is not a problem with pip but with setup.py but can not find anything,

any help would be welcomed

Thanks

Genocide answered 26/3, 2022 at 19:41 Comment(7)
Did you read the message? It tells you you could try psycopg2-binary instead. That package will still install psycopg2 as far as Python is concerned.Lemons
AKX I did try, even I first tried installing psycopg2-binary before just pscopg2, because I do have an environment in windows and linux, and linux required to install psycopg2-binary instead of just psycopg2. But yes, I triedGenocide
What do you mean with "environment in windows and Linux"? How does that relate to your MacBook? (Is it an Intel machine or with Apple Silicon?)Lemons
Yes, it is an apple silicon, it is the M1, and when I said the environment I meant that I have everything working fine, everything installed and working perfectly, including psycopg2, Im new to MacOS so Im struggling with some installationsGenocide
This issue might help, then. I found it by googling psycopg2 m1. github.com/psycopg/psycopg2/issues/1286Lemons
i have the same problem, any solution? the answer from the above link doesn't work.Abhorrent
I have the same problem on an Apple MacBookPro M1Waldner
H
12

As Alex mentioned, it is PostGreSQL being not installed on your system that throws up the error Install PostGreSQL and it will all work fine Try this

❯ brew install postgresql
# If you open a new terminal tab you will see that pg_config is available
❯ export CPPFLAGS="-I/opt/homebrew/opt/[email protected]/include"
❯ export LDFLAGS="-L/opt/homebrew/opt/[email protected]/lib -L${HOME}/.pyenv/versions/3.8.10/lib"
❯ python -V
Python 3.9.13
❯ pip install psycopg2-binary==2.8.6```
Hardie answered 20/7, 2022 at 6:56 Comment(1)
brew install postgresql was enough for me, thank youEnsphere
J
9

Try using the following command:

pip3 install psycopg2-binary
Jeromejeromy answered 1/6, 2022 at 22:27 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Triparted
M
3

Late, but I just had this problem and nothing I was finding was fixing it. I was trying to install the requirements.txt for an ongoing project on a new Mac. Eventually I remembered it's a postgresql package and I hadn't installed postgresql yet. As soon as I installed postgresql and tried installing psycopg2 again, it worked fine with no errors.

Mitigate answered 10/6, 2022 at 2:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.