1

I set the virtualenv for my project and when I want to run

pip install psycopg2

I get an error below

ERROR: Complete output from command python setup.py egg_info:
ERROR: running egg_info
creating pip-egg-info/psycopg2.egg-info
writing pip-egg-info/psycopg2.egg-info/PKG-INFO
writing dependency_links to pip-egg-info/psycopg2.egg-info/dependency_links.txt
writing top-level names to pip-egg-info/psycopg2.egg-info/top_level.txt
writing manifest file 'pip-egg-info/psycopg2.egg-info/SOURCES.txt'

Error: pg_config executable not found.

pg_config is required to build psycopg2 from the 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 "python setup.py egg_info" failed with error code 1 in /private/var/folders/r5/mt37g42j2h3b676lpx3qlznm0000gn/T/pip-install-yijundiy/psycopg2/

after that, I run brew install postgresql and then when I wanted to run :

pip install psycopg2 I got this error:

Running setup.py install for psycopg2 ... error
      Running setup.py install for psycopg2 ... error
        ERROR: Complete output from command 
    ERROR: Command "/Users/masoudmk/Desktop/Masoud/projectenv/bin/python3.7 -u -c 'import setuptools, tokenize;__file__='"'"'/private/tmp/pip-install-6qi9xbe0/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/tmp/pip-record-t8hmiffn/install-record.txt --single-version-externally-managed --compile --install-headers /Users/masoudmk/Desktop/Masoud/projectenv/bin/../include/site/python3.7/psycopg2" failed with error code 1 in /private/tmp/pip-install-6qi9xbe0/psycopg2/

In addition, when I use this command

sudo python setup.py install

I get this error too:

(null): can't open file 'setup.py': [Errno 2] No such file or directory

What should I do!?

Masoud Khani
  • 37
  • 3
  • 10
  • 1
    Possible duplicate of [install Psycopg2 on mac osx 10.9.5](https://stackoverflow.com/questions/33866695/install-psycopg2-on-mac-osx-10-9-5) – Dino May 24 '19 at 14:44

2 Answers2

9

get a stand-alone package

run pip install psycopg2-binary

Samsul Islam
  • 2,581
  • 2
  • 17
  • 23
Pheega
  • 126
  • 3
3

I think you don't have Postgres installed, you can install by using

brew install postgresql

that helps your problem. after that, you can install pip dependency packages

Sanjay Kumar
  • 129
  • 7