我使用的架构仅支持 Windows 系统。我已经为 CI/CD 设置了一个 Jenkins 服务器。我在 Docker 中使用 Wine 和 Ubuntu:20.04 来构建我的源代码并将其打包到 Jenkins 上。
我还希望 Python3.8 能够使我的构建工作,因此我使用嵌入式 Python(在 Wine 上安装 .msi Python 安装程序时遇到问题)。现在,我需要一些未随附的软件包,必须使用 PIP 安装。经过几次搜索,我得知嵌入式 Python 没有官方的 PIP 支持,但通过一些技巧,我们可以让它工作。我尝试了解决方案,它起作用了,但我无法安装一些库,例如 uuid。
FROM ubuntu:20.04
RUN dpkg --add-architecture i386
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update \
&& apt-get install gnupg2 wget software-properties-common -y \
&& wget -nc https://dl.winehq.org/wine-builds/winehq.key \
&& apt-key add winehq.key \
&& apt-add-repository 'deb https://dl.winehq.org/wine-builds/ubuntu/ focal main' \
&& apt-get install -y --no-install-recommends winehq-stable
RUN wine --version
RUN mkdir -p /wine/python
RUN cd /wine/python \
&& wget https://www.python.org/ftp/python/3.8.8/python-3.8.8-embed-amd64.zip \
&& unzip python-3.8.8-embed-amd64.zip \
&& rm -f python-3.8.8-embed-amd64.zip
ENV WINEPREFIX /wine
ENV WINEPATH Z:\\wine\\python\\Scripts;Z:\\wine\\python
# A hack to make pip work with embedded python.
ENV WINEARCH win64
ENV WINEDEBUG fixme-all
RUN wineboot --init
RUN cd /wine/python \
&& mv python38._pth python38._pth.backup \
&& wget https://bootstrap.pypa.io/get-pip.py
RUN wineboot --restart
# We need to provide random value to initialize Python during docker build
ENV PYTHONHASHSEED=4294967295
RUN cd /wine/python \
&& wine cmd /c python --version \
&& wine cmd /c python get-pip.py
RUN wine cmd /c python -m pip --help
RUN wine cmd /c pip3 install uuid
RUN ls /wine/python/Scripts
安装 uuid 不起作用:
Step 24/27 : RUN cd /scratch/wine/python && wine cmd /c python --version && wine cmd /c python get-pip.py
---> Using cache
---> c18f16be8ed0
Step 25/27 : RUN wine cmd /c python -m pip --help
---> Using cache
---> 7599ef6a410d
Step 26/27 : RUN wine cmd /c pip3 install uuid
---> Running in 3df04cc0faa4
Collecting uuid
ERROR: Could not install packages due to an OSError: [WinError -2146893801] Windows Error 0x80090017
有人能帮帮我吗?
答案1
问题归结为 的问题os.urandom()
。如果你wine pip install -v uuid
在容器中运行,你会看到有问题的行:File "uuid.py", line 782, in uuid4
。该行使用os.urandom()
。
这个问题可以通过以下方式重现:wine python -c 'import os; os.urandom(1)'
os.urandom
s文档提到了底层函数的改变从CryptGenRandom()
到BCryptGenRandom()
从 Python 3.11 开始。将示例更改为使用 Python 3.11 可修复此问题:
FROM debian:bookworm
RUN dpkg --add-architecture i386
RUN apt-get update \
&& apt-get install -y --no-install-recommends wine wine32:i386 \
unzip wget ca-certificates
RUN mkdir -p /wine/python
RUN cd /wine/python \
&& wget https://www.python.org/ftp/python/3.11.4/python-3.11.4-embed-win32.zip \
&& unzip python-*.zip \
&& rm -f python-*.zip
ENV WINEPREFIX /wine
ENV WINEPATH Z:\\wine\\python\\Scripts;Z:\\wine\\python
RUN cd /wine/python \
&& rm python*._pth \
&& wget https://bootstrap.pypa.io/get-pip.py
RUN wineboot --init
RUN wineboot --restart
# We need to provide random value to initialize Python during docker build
ENV PYTHONHASHSEED=4294967295
RUN cd /wine/python \
&& wine python --version \
&& wine python get-pip.py
RUN wine python -m pip --help
RUN wine pip3 install uuid
RUN ls /wine/python/Scripts