1

I am trying to put my app that I created on server www using heroku. But when I put to my terminal on Ubuntu pip install psycopg2==2.7.*, I get this error:

ERROR: Command errored out with exit status 1:
     command: /home/marcin/Python/learning_log/ll_env/bin/python3 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-c67buptz/psycopg2/setup.py'"'"'; __file__='"'"'/tmp/pip-install-c67buptz/psycopg2/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-install-c67buptz/psycopg2/pip-egg-info
         cwd: /tmp/pip-install-c67buptz/psycopg2/
    Complete output (28 lines):
    running egg_info
    creating /tmp/pip-install-c67buptz/psycopg2/pip-egg-info/psycopg2.egg-info
    writing /tmp/pip-install-c67buptz/psycopg2/pip-egg-info/psycopg2.egg-info/PKG-INFO
    writing dependency_links to /tmp/pip-install-c67buptz/psycopg2/pip-egg-info/psycopg2.egg-info/dependency_links.txt
    writing top-level names to /tmp/pip-install-c67buptz/psycopg2/pip-egg-info/psycopg2.egg-info/top_level.txt
    writing manifest file '/tmp/pip-install-c67buptz/psycopg2/pip-egg-info/psycopg2.egg-info/SOURCES.txt'
    /home/marcin/Python/learning_log/ll_env/lib/python3.8/site-packages/setuptools/config/setupcfg.py:508: SetuptoolsDeprecationWarning: The license_file parameter is deprecated, use license_files instead.
      warnings.warn(msg, warning_class)
    /home/marcin/Python/learning_log/ll_env/lib/python3.8/site-packages/setuptools/command/egg_info.py:643: SetuptoolsDeprecationWarning: Custom 'build_py' does not implement 'get_data_files_without_manifest'.
    Please extend command classes from setuptools instead of distutils.
      warnings.warn(
    
    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.

What should I do?

Marcin Sochacki
  • 35
  • 1
  • 1
  • 3
  • 1
    https://stackoverflow.com/a/5450183/11544538 – Ersain Sep 02 '22 at 09:51
  • Does this answer your question? [How to install psycopg2 with "pip" on Python?](https://stackoverflow.com/questions/5420789/how-to-install-psycopg2-with-pip-on-python) – phd Sep 12 '22 at 16:23

3 Answers3

4

You need some dependencies check this answer https://stackoverflow.com/a/46877364/15208727

sudo apt install libpq-dev python3-dev
Guna
  • 820
  • 6
  • 21
1

I was able to fix the same issue by installing the Psycopg2 pre-requisites using the following commands on Debian.

pip install python3-dev
sudo apt install libpq-dev libpq-dev

Then confirming pg_config is in my path by doing pg_config --version.

For reference, here's the relevant section from the docs.

Build prerequisites

The build prerequisites are to be met in order to install Psycopg from source code, from a source distribution package, GitHub or from PyPI.

Psycopg is a C wrapper around the libpq PostgreSQL client library. To install it from sources you will need:

  • A C compiler.

  • The Python header files. They are usually installed in a package such as python-dev or python3-dev. A message such as error: Python.h: No such file or directory is an indication that the Python headers are missing.

  • The libpq header files. They are usually installed in a package such as libpq-dev. If you get an error: libpq-fe.h: No such file or directory you are missing them.

  • The pg_config program: it is usually installed by the libpq-dev package but sometimes it is not in a PATH directory. Having it in the PATH greatly streamlines the installation, so try running pg_config --version: if it returns an error or an unexpected version number then locate the directory containing the pg_config shipped with the right libpq version (usually /usr/lib/postgresql/X.Y/bin/) and add it to the PATH:

    $ export PATH=/usr/lib/postgresql/X.Y/bin/:$PATH

    You only need pg_config to compile psycopg2, not for its regular usage.

MikeyE
  • 1,756
  • 1
  • 18
  • 37
0

You should install pscopg2-binary and the push to heroku

pip install psycopg2-binary or pipenv install psycopg2-binary depending on your virtualenv

Martins
  • 1,130
  • 10
  • 26