0

I am using an architecture which supports Windows system only. I have setup a Jenkins server for CI/CD. I am using Wine with Ubuntu:20.04 in Docker to build my source and package it on Jenkins.

I also wanted Python3.8 to make my builds work, so I am using embed python (Had faced issues while installing .msi python installer on Wine). Now, I require few packages that does not come with and has to be installed using PIP. Upon few searches I came to know that there is no official PIP support for embed python, but with few hacks, we can make it work. I tried the solutions, it worked, but I am unable to install few libraries like 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

Installing uuid does not work:

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

Can anyone help me, please?

2
  • so are all these backflips you are doing just to avoid using Windows, but use windows-only python components? I usually think of python as being pretty cross-compatible, so its surprising to me that you cant just use a linux-native instance of python runtime. Commented Sep 13, 2022 at 19:39
  • Yes, that's true but funny at the same time, but for CI/CD, as we want to develop a smooth process. Due to few limitations, I am unable to use Windows docker image, and has to use Wine with Ubuntu. Commented Sep 14, 2022 at 8:03

1 Answer 1

2

The issue boils down to a problem with os.urandom(). If you run wine pip install -v uuid in your container you will see the offending line: File "uuid.py", line 782, in uuid4. That line uses os.urandom().

The issue can be reproduced with wine python -c 'import os; os.urandom(1)'

os.urandoms documentation is mentioning a change of the underlying function from CryptGenRandom() to BCryptGenRandom() starting from Python 3.11. Changing your example to use Python 3.11 fixes the issue:

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

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.