我有一个小的Dockerfile,我想在这个Dockerfile中达到一个点,让我可以 RUN pip3 bdist_wheel
成功。也就是说,没有得到这个错误。
unknown command "bdist_wheel" - maybe you meant "wheel"
我已经尝试安装了在 本回答但没有运气。
最小的重现Docker文件和 docker build
产出:
FROM ubuntu:18.04
RUN apt-get update \
&& apt-get install -qyy -o APT::Install-Recommends=false -o APT::Install-Suggests=false \
file \
gcc \
python3 \
python3-dev \
python3-pip \
python3-setuptools \
python3-venv \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
RUN pip3 install --cache-dir=/tmp/pipcache --upgrade pip && rm -rf /tmp/pipcache
RUN pip install --cache-dir=/tmp/pipcache poetry && rm -rf /tmp/pipcache
WORKDIR /src/app
RUN poetry new .
RUN poetry add gevent
产出中最相关的部分当然是......。
错误:无效命令'bdist_wheel'。
首先,我想说的是 error: invalid command 'bdist_wheel'
输出。当运行 pip install <pkgname>
, pip
将尝试找到一个与你的目标平台相匹配的预制轮子。如果找不到,它就会尝试自己制作一个轮子 -- 下载源码并 pip wheel
是运行生产轮子。成功时,安装好的轮子。在任何失败的情况下(该 wheel
包未安装。python setup.py bdist_wheel
失败或什么的)。) pip
将回退到第二个选项,即 distutils
安装方法:运行 python setup.py install
在解压后的源码上。这就是你发布的日志中可以观察到的。
Failed building wheel for gevent
...
Running setup.py install for gevent: started
只有当... setup.py install
也失败,安装无条件失败。所以当 pip
不可能真的造出轮子来 wheel
包没有安装,这不是安装失败的问题。您可以通过添加 wheel
到开发包。
RUN poetry add --dev wheel
RUN poetry add gevent
但这是一个可选的东西,不会影响构建结果。
现在,说说真正的错误。
Running '(cd "/tmp/pip-build-ek9pxyw2/gevent/deps/libev" && sh ./configure -C > configure-output.txt )' in /tmp/pip-build-ek9pxyw2/gevent
config.status: error: in `/tmp/pip-build-ek9pxyw2/gevent/deps/libev':
config.status: error: Something went wrong bootstrapping makefile fragments
for automatic dependency tracking. Try re-running configure with the
'--disable-dependency-tracking' option to at least be able to build
the package (albeit without support for automatic dependency tracking).
See `config.log' for more details
Something went wrong bootstrapping makefile fragments
通常意味着你缺少了 make
. 除了其他的,还要安装它。
RUN apt install -y make
这样做后,重新运行编译,我得到了最后一个错误的信息
error: src/gevent/libev/corecext.c: No such file or directory
这是因为 gevent
需要Cython来生成C扩展源。在安装之前,请先安装 gevent
:
RUN poetry add --dev cython
RUN poetry add gevent
完整的Docker文件供参考,变化为粗体。
FROM ubuntu:18.04
RUN apt-get update \
&& apt-get install -qyy -o APT::Install-Recommends=false -o APT::Install-Suggests=false \
file \
gcc \
python3 \
python3-dev \
python3-pip \
python3-setuptools \
python3-venv \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
RUN pip3 install --cache-dir=/tmp/pipcache --upgrade pip && rm -rf /tmp/pipcache
RUN pip install --cache-dir=/tmp/pipcache poetry && rm -rf /tmp/pipcache
WORKDIR /src/app
RUN poetry new .
RUN apt update
RUN apt install -y make
RUN poetry add --dev wheel cython
RUN poetry add gevent
既不是 wheel
也不 cython
需要实际运行 gevent
因此,他们可以安全地卸载后,以减少图像大小。