gpt4 book ai didi

python - docker中python虚拟环境GCC错误

转载 作者:行者123 更新时间:2023-12-01 08:35:35 51 4
gpt4 key购买 nike

我有一个 docker 文件,我在其中在 python 2.7.15 中创建虚拟环境并为我的项目安装所有必需的 python 依赖项。

一些依赖项需要 gcc 来编译,如 pandas、lz4 .. 失败并出现以下错误,

 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

即使我厌倦了在 docker 中安装 python-devel 和 gcc 。但没有帮助。

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

如何解决这个问题。

最佳答案

我想你应该:

  1. 安装 python 开发文件(如评论中的建议)。
  2. gcc 命令行中使用 -I 开关来指向 python 包含文件的正确路径。

关于python - docker中python虚拟环境GCC错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53738715/

51 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com