0

I am trying to install ibm_db - python3.6 but not able to do pip install. On python 2.7 the installation is successful but on 3.6 its throwing gcc error

Docker File

RUN yum -y install python3
RUN yum install -y python34-devel python-devel centos-release-scl gcc libssl-dev openssl yum install gcc openssl-devel bzip2-devel libffi libffi-devel
RUN yum install -y python gcc gcc-c++ libgcc libstdc++ gnupg wget make git
RUN python --version
RUN which python
RUN pip --version
RUN python3 --version
RUN which python3
RUN pip3 --version

RUN python3.6 -m pip install -r scripts/requirements.txt

Requirements.txt

ibm_db==3.0.2
ibm-db-sa==0.3.5
SQLAlchemy==1.3.18

logs

08-Aug-2020 07:57:40        building 'ibm_db' extension
08-Aug-2020 07:57:40        creating build/temp.linux-x86_64-3.6
08-Aug-2020 07:57:40        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 -Iclidriver/include -I/usr/include/python3.6m -c ibm_db.c -o build/temp.linux-x86_64-3.6/ibm_db.o
08-Aug-2020 07:57:40        ibm_db.c:27:20: fatal error: Python.h: No such file or directory
08-Aug-2020 07:57:40         #include <Python.h>
08-Aug-2020 07:57:40                            ^
08-Aug-2020 07:57:40        compilation terminated.
08-Aug-2020 07:57:40        error: command 'gcc' failed with exit status 1
08-Aug-2020 07:57:40        
08-Aug-2020 07:57:40        ----------------------------------------
08-Aug-2020 07:57:40    Command "/usr/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-fvpot_ia/ibm-db/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-yrktaypy-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-fvpot_ia/ibm-db/
08-Aug-2020 07:57:42    The command '/bin/sh -c python3.6 -m pip install -r scripts/requirements.txt' returned a non-zero code: 1
08-Aug-2020 07:57:42    make: *** [build] Error 1
Gourab Paul
  • 575
  • 7
  • 14
  • Odd. Normally if "Python.h" can't be found, it would mean that python-devel isn't installed. But here I can see that you are yum installing it. –  Aug 08 '20 at 08:13
  • Why python34-devel with python36? – mao Aug 08 '20 at 08:14
  • Is there a "python3-devel" package that you can yum install? I am thinking that possibly "python-devel" is for python 2, and we know that it is using 3.6 so python34-devel won't be relevant. –  Aug 08 '20 at 08:15
  • @mao I am guessing that 3.6 is the "base" python3 and that the python34-devel is a co-existing compatibility version that can be installed. –  Aug 08 '20 at 08:16
  • Separately, I see that there is both "python" and "python3" in terms of the run-time packages, so this supports my hypothesis that the base python package is python2. RedHat / CentOS seem to be still building their OS on python2 -- but why? –  Aug 08 '20 at 08:18

1 Answers1

0

The Dockerfile below is for an image to current versions of ibm_db and ibm_db_sa and SQLAlchemy for centos7 .

It works for x64 architecture without needing to compile ibm_db.

Change the Dockerfile to omit the packages that you do not need in your image. Smaller images build quicker and use less storage.

This Dockerfile shows an optional step to copy a preconfigured db2dsdriver.cfg into the image to the default location.

This lets me use db2cli in the container to ensure connectivity to databases before using python ibm_db.

db2cli needs LD_LIBRARY_PATH to contain the clidriver\lib directory, to ensure db2cli validate will run.

 FROM centos:7


     RUN yum install -y \
       pam-devel \
       pam.i686 \
       libaio \
       libstdc++-devel.i686 \
       numactl-libs \
       gcc \
       gcc-c++ \
       ksh \
       numactl \
       file \
       kernel-devel \
       vi \
       sudo \
       util-linux \
       which \
       openssh-clients \
       zip \
       unzip \
       python3 \
       python3-devel \
       libssl_dev \
       openssl \
       openssl-devel \
       bzip2-devel \
       libffi \
       libffi-devel \
       libgcc \
       wget \
       make \
       git \
       libxml2 \
       && yum -y update \
       && yum clean all \
       && python3 -m pip install --upgrade pip \
       && python3 -m pip install ibm_db \
       && python3 -m pip install ibm_db_sa 
    
    ENV LD_LIBRARY_PATH="/usr/local/lib64/python3.6/site-packages/clidriver/lib:${LD_LIBRARY_PATH}"
    
    # Optional - copy a preconfigured db2dsdriver.cfg to the image default location for db2cli to work
    COPY db2dsdriver.cfg /usr/local/lib64/python3.6/site-packages/clidriver/cfg
mao
  • 11,321
  • 2
  • 13
  • 29