gpt4 book ai didi

python - 无法在 python :3. 4 docker 容器中导入 lxml

转载 作者:行者123 更新时间:2023-11-28 17:34:40 26 4
gpt4 key购买 nike

很可能是由于资源限制,我无法在基于 python:3.4 的 docker 容器中 pip 安装(并因此构建)lxml。

因此我安装了这个包。我的 Dockerfile:

FROM python:3.4
COPY ./ /source
RUN apt-get update
RUN apt-get install -y python3-lxml
RUN pip install -r /source/requirements.txt

不幸的是,我无法import lxml,即使只是在我的容器中运行 Python,就像这样:

***@*****:/web/source# docker exec -i -t 84c4cbf09321 python
Python 3.4.3 (default, May 26 2015, 19:20:24)
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import lxml
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'lxml'
>>>

如何解决?

最佳答案

您的问题是您使用的是 python图像,它将 从源 安装 Python 到 /usr/local .然后您正在尝试安装 lxml使用系统包管理器的模块,apt-get .这将安装 lxml/usr/bin/ 中,系统 Python 可以看到它,但/usr/local中的源安装Python .您有几个选择:

  • 不要尝试将 Python 包管理器 ( pip ) 与系统包管理器混合使用。就pip install一切。我试过了,令我惊讶的是我可以成功 pip install lxml (我没想到所有构建依赖项都到位了,但显然它们是到位了)。

  • 不要费心使用 python图像。只需从您最喜欢的发行版(Fedora、Ubuntu 等)开始,然后使用系统包管理器:

    FROM ubuntu
    RUN apt-get install -y python3-lxml

    对于最近的 Ubuntu 镜像,这将为您提供 Python 3.4.2(注意:称为 python3),这与安装在 python 上的 3.4.3 相比只有一个小的修订版。图片。

关于python - 无法在 python :3. 4 docker 容器中导入 lxml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31728132/

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