-3

When I'm trying to install the requirements for a project with pip install -r requirements.txt It keeps failing with the following output.

[sarthak@envy cyc1eon]$ pip install -r requirements.txt
Defaulting to user installation because normal site-packages is not writeable
Collecting asgiref==3.2.10
  Downloading asgiref-3.2.10-py3-none-any.whl (19 kB)
Collecting dj-database-url==0.5.0
  Downloading dj_database_url-0.5.0-py2.py3-none-any.whl (5.5 kB)
Collecting Django==3.0.8
  Downloading Django-3.0.8-py3-none-any.whl (7.5 MB)
     |████████████████████████████████| 7.5 MB 2.6 MB/s 
Collecting django-heroku==0.3.1
  Downloading django_heroku-0.3.1-py2.py3-none-any.whl (6.2 kB)
Collecting gunicorn==20.0.4
  Downloading gunicorn-20.0.4-py2.py3-none-any.whl (77 kB)
     |████████████████████████████████| 77 kB 5.5 MB/s 
Requirement already satisfied: setuptools>=3.0 in /usr/lib/python3.9/site-packages (from gunicorn==20.0.4->-r requirements.txt (line 5)) (54.2.0)
Collecting psycopg2==2.8.5
  Downloading psycopg2-2.8.5.tar.gz (380 kB)
     |████████████████████████████████| 380 kB 9.7 MB/s 
    ERROR: Command errored out with exit status 1:
     command: /usr/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-lc8h8hyn/psycopg2_4a4c96a147204fd489df1a2f7201063a/setup.py'"'"'; __file__='"'"'/tmp/pip-install-lc8h8hyn/psycopg2_4a4c96a147204fd489df1a2f7201063a/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-ztzh9r6w
         cwd: /tmp/pip-install-lc8h8hyn/psycopg2_4a4c96a147204fd489df1a2f7201063a/
    Complete output (23 lines):
    running egg_info
    creating /tmp/pip-pip-egg-info-ztzh9r6w/psycopg2.egg-info
    writing /tmp/pip-pip-egg-info-ztzh9r6w/psycopg2.egg-info/PKG-INFO
    writing dependency_links to /tmp/pip-pip-egg-info-ztzh9r6w/psycopg2.egg-info/dependency_links.txt
    writing top-level names to /tmp/pip-pip-egg-info-ztzh9r6w/psycopg2.egg-info/top_level.txt
    writing manifest file '/tmp/pip-pip-egg-info-ztzh9r6w/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>).
    
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

The requirements for the project are

asgiref==3.2.10
dj-database-url==0.5.0
Django==3.0.8
django-heroku==0.3.1
gunicorn==20.0.4
psycopg2==2.8.5
psycopg2-binary==2.8.5
python-decouple==3.3
pytz==2020.1
sqlparse==0.3.1
whitenoise==5.1.0

  • remove `psycopg2==2.8.5` from `requirements.txt` – buran Apr 17 '21 at 11:30
  • 1
    Does this answer your question? [Error trying to install Postgres for python (psycopg2)](https://stackoverflow.com/questions/22938679/error-trying-to-install-postgres-for-python-psycopg2) – frost-nzcr4 Apr 17 '21 at 11:48

2 Answers2

1

The error message is clear - missing pg-config and thus unable to build from source. Alternative to building from source is to use psycorg2-binary - already present in the requirements.txt and suggested in the error message itself:

If you prefer to avoid building psycopg2 from source, please install the PyPI 'psycopg2-binary' package instead

Just remove psycopg2==2.8.5 from requirements.txt.

Alternatively check pg_config executable not found

buran
  • 13,682
  • 10
  • 36
  • 61
-1

try replacing:

asgiref==3.2.10
dj-database-url==0.5.0
Django==3.0.8
django-heroku==0.3.1
gunicorn==20.0.4
psycopg2==2.8.5
psycopg2-binary==2.8.5
python-decouple==3.3
pytz==2020.1
sqlparse==0.3.1
whitenoise==5.1.0

in requirements.txt by:

asgiref
dj-database-url
Django
django-heroku
gunicorn
psycopg2
psycopg2-binary
python-decouple
pytz
sqlparse
whitenoise
  • How this will help at all? – buran Apr 17 '21 at 11:30
  • @buran well since he got a problem with `psycopg2-2.8.5 ` i thought maybe 2-2.8.5 was an older version. you never know – youssef jallouli Apr 17 '21 at 11:33
  • well, the error message is clear - missing `pg-config` and thus unable to build from source. Alternative to building from source is to use `psycorg2-binary` - already present in the requirments.txt. And generally removing package version when specified is bad idea and can cause much bigger problems - e.g. incompatibility, etc. – buran Apr 17 '21 at 11:35
  • Tried it, didn't work. – Sarthak Dhonchak Apr 17 '21 at 11:35
  • @buran his program will need that module to work though ? – youssef jallouli Apr 17 '21 at 11:39
  • @youssefjallouli `psycorg2-binary` is the same package, available pre-build on PyPI. It's the suggestion in the error message itself. – buran Apr 17 '21 at 11:40