how to install python3 in wine?

How can we install python3 in wine for 32bit ubuntu ?

Using winetricks python2.7 is possible but my app is written in python3

I don't have windows to test my application so I am going this hard way


Python 3.7 now works in the newer versions of wine. This user used wine 4.14 to install python 3.7.4 and I'm currently using Python 3.7.6 in wine 5.0-rc3. I'm able to run pyinstaller for cross-compiling and I can test the resulting exe packages and my source code in wine without issue. The apps I'm testing have a GUI based on PyQt5.

I first tried @Hibou57's approach using embedded-python which does not require newer wine versions. While this works for a minimal python install, I ran into a lot of annoying problems later on requiring a number of hacks. I gave up on this approach when I couldn't figure out how to install numpy within embedded python in wine.

To install Python 3.7.6 in wine:

  1. Add the official wine repository to apt to get the lastest dev versions
  2. Install the developer version of wine sudo apt install winehq-devel.
  3. Just download and run the Python 3.7.6 exe install file within wine wine cmd /c python-3.7.6.exe.

The script below is what I'm using to install python 3.7.6 inside a docker container for cross compiling using a Ubuntu 18.04 image. I'm also using a 64-bit wine prefix. Note that some parts of this script deal with docker-specific issues.

#!/bin/bash

set -e

echo "---------------------------------"
echo "-------- setup wine prefix ------"
echo "---------------------------------"
# We need the developer version of wine.  We need at least version 4.14 (see link).
# This is the earliest version I've seen reported to work with python3 well
# Without this, we'd have to run the embedded install of python which is riddled
# with annoying issues.

# see: https://appdb.winehq.org/objectManager.php?sClass=version&iId=38187

echo "------ Installing required apt packages ------"
apt update
apt install -y wget gnupg software-properties-common apt-utils

echo "------ Add latest wine repo ------"
# Need at least wine 4.14 to install python 3.7
dpkg --add-architecture i386
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/ bionic main'
apt update

# Add repo for faudio package.  Required for winedev
add-apt-repository -y ppa:cybermax-dexter/sdl2-backport

echo "-------- Install wine-dev ------"

apt install -y \
    winehq-devel \
    winetricks \
    xvfb        # This is for making a dummy X server disply 

echo "------ Download python ------"
wget https://www.python.org/ftp/python/3.7.6/python-3.7.6-amd64.exe
#wget https://www.python.org/ftp/python/3.7.6/python-3.7.6.exe

echo "------ Init wine prefix ------"
WINEPREFIX=~/.wine64 WINARCH=win64 winetricks \
    corefonts \
    win10

# Setup dummy screen
Xvfb :0 -screen 0 1024x768x16 &
jid=$!

echo "------ Install python ------"
DISPLAY=:0.0 WINEPREFIX=~/.wine64 wine cmd /c \
    python-3.7.6-amd64.exe \
    /quiet \
    PrependPath=1 \
    && echo "Python Installation complete!"
# Display=:0.0 redirects wine graphical output to the dummy display.  
# This is to avoid docker errors as the python installer requires a display, 
# even when quiet install is specified.

I have a similar issue: I have to develop a Python3 application on Ubuntu which is to be delivered on Windows. I wanted to use pyInstaller to produce a Windows executable from Wine, since I unfortunately do not have access to a Windows box. But I failed to install Python3 on Wine too.

However, may be there is another option: using what’s called a python embeddable zip archive. See here: 3.8. Embedded Distribution (docs.python.org).

You can download it from releases download pages, as in this one (an example) : Python 3.5.2 (python.org).

You have two:

  • Windows x86-64 embeddable zip file
  • Windows x86 embeddable zip file

This means you have to ask the client if he/she is running a 32 bits or a 64 bits Windows.

That’s not perfect, since if Python3 is not able to run in Wine, there is no way to test the application’s Windows version. But at least, that’s a way to package something which should run on Windows, with the hope the source will behave on Windows the same way it behave on Ubuntu. At least, you should develop on the Ubuntu side, using a Python virtual environment. See 28.3. venv — Creation of virtual environments.