1

I have a docker file where i am creating a virtual environment in python 2.7.15 and installing all required python dependencies for my project.

Some of the dependencies require gcc to compile like pandas, lz4 .. are failing with below error,

 pandas/io/sas/sas.c:4:20: fatal error: Python.h: No such file or directory
     #include "Python.h"
                        ^
    compilation terminated.
    error: command 'gcc' failed with exit status 1

Even i tired installing python-devel , gcc also in the docker. But doesn't help.

RUN yum install -y python-pip python-devel gcc

Dockerfile:

FROM registry-access-redhat-com.repo.lab.pl.*-*.com/rhel7.5

# CONFIGURE YUM
RUN rm -f /etc/yum.repos.d/*
ADD resources/yum.repos.d/* /etc/yum.repos.d/
RUN echo "sslverify=false" >> /etc/yum.conf

# INSTALL REQUIRED SYSTEM PACKAGES 
RUN yum install -y python-pip python-devel gcc && yum clean all && rm -rf /var/cache/yum
RUN yum install -y wget && yum clean all && rm -rf /var/cache/yum && wget http://repo.lab.pl.alcatel-lucent.com/eden-yum-releases/installation-packages-rpm/python-2.7.15-2.x86_64.rpm

RUN yum install -y python-2.7.15-2.x86_64.rpm && yum clean all && rm -rf /var/cache/yum

#DOWNLAOD LATEST PIP
RUN wget -P /tmp/ https://files.pythonhosted.org/packages/c2/d7/90f34cb0d83a6c5631cf71dfe64cc1054598c843a92b400e55675cc2ac37/pip-18.1-py2.py3-none-any.whl

#INSTALL PIP ON PYTHON 2.7.15
RUN LD_LIBRARY_PATH=/usr/local/lib /usr/local/bin/python2.7 /tmp/pip-18.1-py2.py3-none-any.whl/pip install --find-links /tmp --upgrade --no-index /tmp/pip-18.1-py2.py3-none-any.whl

# CREATE foo GROUP AND USER
RUN groupadd foo
RUN useradd -d /home/foo -ms /bin/bash -g foo foo

# SETUP BASHRC for foo user
COPY file/.bashrc /home/foo
COPY file/.bash_profile /home/foo
RUN chown foo:foo /home/foo/.bash_profile
RUN chown foo:foo /home/foo/.bashrc

# SET WORKING DIRECTORY TO /home/foo
WORKDIR /home/foo

#CREATE VIRTUAL ENVIRONMENT
RUN wget -P /tmp/ https://files.pythonhosted.org/packages/e7/16/da8cb8046149d50940c6110310983abb359bbb8cbc3539e6bef95c29428a/setuptools-40.6.2-py2.py3-none-any.whl
RUN wget -P /tmp/ https://files.pythonhosted.org/packages/7c/17/9b7b6cddfd255388b58c61e25b091047f6814183e1d63741c8df8dcd65a2/virtualenv-16.1.0-py2.py3-none-any.whl
RUN LD_LIBRARY_PATH=/usr/local/lib /usr/local/bin/python2.7 /tmp/pip-18.1-py2.py3-none-any.whl/pip install --find-links /tmp --upgrade --no-index /tmp/virtualenv-16.1.0-py2.py3-none-any.whl
RUN LD_LIBRARY_PATH=/usr/local/lib /usr/local/bin/python2.7 /tmp/pip-18.1-py2.py3-none-any.whl/pip install --find-links /tmp --upgrade --no-index /tmp/setuptools-40.6.2-py2.py3-none-any.whl
RUN LD_LIBRARY_PATH=/usr/local/lib /usr/local/bin/virtualenv -p /usr/local/bin/python2.7 enet
RUN chown -R foo:foo /home/foo/enet
RUN export LD_LIBRARY_PATH=/usr/local/lib
RUN source /home/foo/enet/bin/activate
RUN LD_LIBRARY_PATH=/usr/local/lib /home/foo/enet/bin/python2.7 /tmp/pip-18.1-py2.py3-none-any.whl/pip install --find-links /tmp --upgrade --no-index /tmp/pip-18.1-py2.py3-none-any.whl

RUN LD_LIBRARY_PATH=/usr/local/lib /home/foo/enet/bin/python2.7 /tmp/pip-18.1-py2.py3-none-any.whl/pip install scipy
RUN LD_LIBRARY_PATH=/usr/local/lib /home/foo/enet/bin/python2.7 /tmp/pip-18.1-py2.py3-none-any.whl/pip install openpyxl
RUN LD_LIBRARY_PATH=/usr/local/lib /home/foo/enet/bin/python2.7 /tmp/pip-18.1-py2.py3-none-any.whl/pip install confluent-kafka

RUN LD_LIBRARY_PATH=/usr/local/lib /home/foo/enet/bin/python2.7 /tmp/pip-18.1-py2.py3-none-any.whl/pip install cython

RUN LD_LIBRARY_PATH=/usr/local/lib /home/foo/enet/bin/python2.7 /tmp/pip-18.1-py2.py3-none-any.whl/pip install pandas

RUN LD_LIBRARY_PATH=/usr/local/lib /home/foo/enet/bin/python2.7 /tmp/pip-18.1-py2.py3-none-any.whl/pip install lz4

How can i resolve this issue.

4
  • Can you post your Dockerfile also? Commented Dec 12, 2018 at 8:26
  • 2
    Try installing specific devel package yum install python27-devel, just in case. Commented Dec 12, 2018 at 9:04
  • 1
    Why the need for a virtual environment in a Docker container? Commented Dec 12, 2018 at 11:25
  • I also recommend deleting the shell dotfiles; they've come up in several SO questions and will not work how you expect. (docker run ... myapp does not launch a shell at all.) Commented Dec 12, 2018 at 12:04

1 Answer 1

1

I guess you should:

  1. Install the python development files (as suggest in comment).
  2. Use a -I switch in gcc command line to point the correct path for python include files.
Sign up to request clarification or add additional context in comments.

4 Comments

And install the developer package with headers before that as vivekyad4v suggests above.
@binarym I tried pip to include header files. but still doesnt work RUN LD_LIBRARY_PATH=/usr/local/lib /usr/local/bin/python2.7 /tmp/pip-18.1-py2.py3-none-any.whl/pip install --global-option=build_ext --global-option="-I/usr/include/python2.7" --global-option="-L/usr/local/lib" pandas. How to use gcc. I am not aware of this. Python.h files are present under /usr/include/python2.7
when i change the LD_LIBRARY PATH to /usr/include/python2.7. pandas module installed successfully but not it my virtualenv path. RUN LD_LIBRARY_PATH=/usr/local/lib /home/foo/enet/bin/python2.7 /tmp/pip-18.1-py2.py3-none-any.whl/pip install pandas. It is installing /usr/lib64
I guess the problem is you specify -I/usr/include/python2.7 but your python installation looks under /usr/local... And note that LD_LIBRARY_PATH is to specify path for dynamic libraries, not include file ;-) You must set up both LD_LIBRARY_PATH and -I correctly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.