python虚拟环境报错_docker中的python虚拟环境中的GCC错误

在Dockerfile中创建Python虚拟环境并安装依赖时遇到编译错误,如pandas和lz4因缺少Python.h头文件导致gcc编译失败。已尝试安装python-devel和gcc,但问题未解决。Dockerfile包含了安装python,pip,setuptools和virtualenv的步骤,并尝试通过pip安装多个库,包括scipy,openpyxl,confluent-kafka,cython,pandas和lz4。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.

解决方案

I guess you should:

Install the python development files (as suggest in comment).

Use a -I switch in gcc command line to point the correct path for python include files.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值