learner57
learner57

Reputation: 491

gcc error while installing psycopg2 on RHEL 7 VM

My environment in RHEL 7, Python 3.6 and Postgres is located on RDS cluster. I am using Pycharm to develop. I did

python -m pip install psycopg2 it gives error

command gcc failed with exit status 1

To rectify, I tried to install psycopg2-binary but I need psycopg2 package to connect to postgres through python script. If I use SQLAlchemy, it directs through the psycopg2 package.

I tried sudo yum install postgresql-libs .... sudo yum install postgresql-devel but the problem persists.

Here's the full error in a picture: enter image description here

Full error:

[priya@localhost psycopg2-2.9.1]$ pip install psycopg2
Defaulting to user installation because normal site-packages is not writeable
Collecting psycopg2
  Using cached psycopg2-2.9.1.tar.gz (379 kB)
Using legacy 'setup.py install' for psycopg2, since package 'wheel' is not installed.
Installing collected packages: psycopg2
    Running setup.py install for psycopg2 ... error
    ERROR: Command errored out with exit status 1:
     command: /usr/bin/python3 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-oe9qfnfj/psycopg2_0348a9316a144cb3bcfec63fc1fb2743/setup.py'"'"'; __file__='"'"'/tmp/pip-install-oe9qfnfj/psycopg2_0348a9316a144cb3bcfec63fc1fb2743/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-2rdr62wb/install-record.txt --single-version-externally-managed --user --prefix= --compile --install-headers /home/priya/.local/include/python3.6m/psycopg2
         cwd: /tmp/pip-install-oe9qfnfj/psycopg2_0348a9316a144cb3bcfec63fc1fb2743/
    Complete output (38 lines):
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.6
    creating build/lib.linux-x86_64-3.6/psycopg2
    copying lib/__init__.py -> build/lib.linux-x86_64-3.6/psycopg2
    copying lib/_ipaddress.py -> build/lib.linux-x86_64-3.6/psycopg2
    copying lib/_json.py -> build/lib.linux-x86_64-3.6/psycopg2
    copying lib/_range.py -> build/lib.linux-x86_64-3.6/psycopg2
    copying lib/errorcodes.py -> build/lib.linux-x86_64-3.6/psycopg2
    copying lib/errors.py -> build/lib.linux-x86_64-3.6/psycopg2
    copying lib/extensions.py -> build/lib.linux-x86_64-3.6/psycopg2
    copying lib/extras.py -> build/lib.linux-x86_64-3.6/psycopg2
    copying lib/pool.py -> build/lib.linux-x86_64-3.6/psycopg2
    copying lib/sql.py -> build/lib.linux-x86_64-3.6/psycopg2
    copying lib/tz.py -> build/lib.linux-x86_64-3.6/psycopg2
    running build_ext
    building 'psycopg2._psycopg' extension
    creating build/temp.linux-x86_64-3.6
    creating build/temp.linux-x86_64-3.6/psycopg
    gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -DPSYCOPG_VERSION=2.9.1 (dt dec pq3 ext) -DPSYCOPG_DEBUG=1 -DPG_VERSION_NUM=90224 -DPSYCOPG_DEBUG=1 -I/usr/include/python3.6m -I. -I/usr/include -I/usr/include/pgsql/server -I/usr/include/libxml2 -c psycopg/psycopgmodule.c -o build/temp.linux-x86_64-3.6/psycopg/psycopgmodule.o -Wdeclaration-after-statement
    In file included from psycopg/psycopgmodule.c:28:0:
    ./psycopg/psycopg.h:35:20: fatal error: Python.h: No such file or directory
     #include <Python.h>
                        ^
    compilation terminated.
   
    It appears you are missing some prerequisite to build the package from source.
   
    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.
   
    For further information please check the 'doc/src/install.rst' file (also at
    <https://www.psycopg.org/docs/install.html>).
   
    error: command 'gcc' failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python3 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-oe9qfnfj/psycopg2_0348a9316a144cb3bcfec63fc1fb2743/setup.py'"'"'; __file__='"'"'/tmp/pip-install-oe9qfnfj/psycopg2_0348a9316a144cb3bcfec63fc1fb2743/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-2rdr62wb/install-record.txt --single-version-externally-managed --user --prefix= --compile --install-headers /home/priya/.local/include/python3.6m/psycopg2 Check the logs for full command output.

Upvotes: 2

Views: 1778

Answers (1)

learner57
learner57

Reputation: 491

Solution:

sudo yum repo-pkgs rhel-7-server-optional-rpms list | grep python3
sudo yum install python3-devel.x86_64 --enablerepo=rhel-7-server-optional-rpms
pip install psycopg2

Courtesy: Jonathan's answer from How to install python3-devel on red hat 7

Upvotes: 3

Related Questions