为什么 setuptools 在使用 Python 和 Linux 的 Ubuntu docker 镜像环境中不可用?开发工具安装了吗?
我正在尝试为机器学习项目构建运行 Python 3.7 的 Ubuntu 18.04 Docker 映像。当使用 requirements.txt
中的 pip
安装特定的 Python 包时,我收到以下错误:
Collecting sklearn==0.0
Downloading sklearn-0.0.tar.gz (1.1 kB)
Preparing metadata (setup.py): started
Preparing metadata (setup.py): finished with status 'error'
error: subprocess-exited-with-error
× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> [1 lines of output]
ERROR: Can not execute `setup.py` since setuptools is not available in the build environment.
[end of output]
虽然这里的错误出现在 sklearn
的上下文中,该问题并非特定于某个图书馆;当我删除该库并尝试重建映像时,其他库会出现错误。
这是我的 Dockerfile
:
FROM ubuntu:18.04
# install python
RUN apt-get update && \
apt-get install --no-install-recommends -y \
python3.7 python3-pip python3.7-dev
# copy requirements
WORKDIR /opt/program
COPY requirements.txt requirements.txt
# install requirements
RUN python3.7 -m pip install --upgrade pip && \
python3.7 -m pip install -r requirements.txt
# set up program in image
COPY . /opt/program
我尝试过的操作:
- 在安装之前安装
python-devtools
,而不是python3.7-dev
并与之一起安装pip
的要求; - 在安装受影响的库之前,在
requirements.txt
中安装setuptools
。
在这两种情况下都出现了相同的错误。
您知道在安装 sklearn
等库时如何确保 setuptools
在我的环境中可用吗?
I'm trying to build a Ubuntu 18.04 Docker image running Python 3.7 for a machine learning project. When installing specific Python packages with pip
from requirements.txt
, I get the following error:
Collecting sklearn==0.0
Downloading sklearn-0.0.tar.gz (1.1 kB)
Preparing metadata (setup.py): started
Preparing metadata (setup.py): finished with status 'error'
error: subprocess-exited-with-error
× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> [1 lines of output]
ERROR: Can not execute `setup.py` since setuptools is not available in the build environment.
[end of output]
Although here the error arises in the context of sklearn
, the issue is not specific to one library; when I remove that libraries and try to rebuild the image, the error arises with other libraries.
Here is my Dockerfile
:
FROM ubuntu:18.04
# install python
RUN apt-get update && \
apt-get install --no-install-recommends -y \
python3.7 python3-pip python3.7-dev
# copy requirements
WORKDIR /opt/program
COPY requirements.txt requirements.txt
# install requirements
RUN python3.7 -m pip install --upgrade pip && \
python3.7 -m pip install -r requirements.txt
# set up program in image
COPY . /opt/program
What I've tried:
- installing
python-devtools
, both instead of and alongside,python3.7-dev
before installing requirements withpip
; - installing
setuptools
inrequirements.txt
before affected libraries are installed.
In both cases the same error arose.
Do you know how I can ensure setuptools
is available in my environment when installing libraries like sklearn
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如评论中所述,在运行
pip install -rrequirements.txt
之前使用pip
安装setuptools
。它与将
setuptools
放在requirements.txt
中的较高位置不同,因为它会强制执行顺序,而需求文件会收集所有包并在之后安装它们,因此您无法控制命令。As mentioned in comment, install
setuptools
withpip
before runningpip install -r requirements.txt
.It is different than putting
setuptools
higher in therequirements.txt
because it forces the order while the requirements file collect all the packages and installs them after so you don't control the order.