How to implement Python EXE for Windows in Docker container

For those who want to quickly EXE the Python code used in Linux on Docker to pass it to others.

Container to use

Some people have distributed a container that runs PyInstaller on windows, so we will use it.

When I read the Dockerfile, it seems that I am using software that runs the following Windows applications on Linux.

--External site: WINE HQ

Explanation of Wine HQ on the TOP of the site (Japanese translation is appropriate, so I don't know)

Wine (originally an acronym for "Wine Is Not an Emulator") is a compatibility layer that allows you to run Windows applications on POSIX-compliant operating systems such as Linux, macOS, and BSD. Rather than simulating internal Windows logic like virtual machines and emulators, Wine translates Windows API calls into POSIX calls on the fly, eliminating performance and memory penalties in other ways and making Windows applications. It can be integrated cleanly into your desktop.

Execution command example

Since it is often executed many times, it is executed as a shell script. If you execute the following shell script in the directory containing the source code, the build, dist directory, and .spec files will be generated in the same hierarchy. The created EXE for Windows is in the dist directory.

build.sh


#! /bin/bash
docker run --rm -v "$(pwd):/src/" --entrypoint /bin/sh cdrx/pyinstaller-windows \
-c "/usr/bin/pip install -r requirements.txt && pyinstaller main.py --noconsole --onefile --clean"

-- docker run: Container execution command -- -rm: Clear container after exiting container ---v "$ (pwd): / src /": Mount the current directory of the host OS to / src / of the container OS -- --entrypoint / bin / sh Specify the person to whom the command is passed when executing (specify sh this time) -- cdrx / pyinstaller-windows: Specify the image to execute. You can also create an executable file for Linux using `cdrx / pyinstaller-linux```. Well, I think you can do it with a normal development container. --``` -c "~ hogehoge ~" `: Specify the command to be executed in the container -- / usr / bin / pip install -r requirements.txt: Install dependencies with pip. Add if you need to install apt etc. -- pyinstaller main.py --noconsole --onefile --clean: The exe conversion command of the main subject. No console, 1 file, specify the option to erase the previous result.

Execution result

So far, I converted about 3 types of code into exe and ran it on win10 and win8, but it started without any problem. Also, the code of PySimpleGUI could be converted to exe without any problem, so I would like to recommend it to those who want to quickly create a GUI for Windows with Python.

Recommended Posts

How to implement Python EXE for Windows in Docker container
How to implement Discord Slash Command in Python
How to install Python [Windows]
How to develop in Python
[For beginners] How to use say command in python!
How to run python in virtual space (for MacOS)
[Python] How to do PCA in Python
How to collect images in Python
How to implement 100 data science knocks for data science beginners (for windows10 Home)
How to define multiple variables in a python for statement
How to use Mysql in python
How to wrap C in Python
How to use ChemSpider in Python
How to use PubChem in Python
How to delete a Docker container
How to handle Japanese in Python
How to log in to Docker + NGINX
[For beginners] How to implement O'reilly sample code in Google Colab
How to configure CORS settings for Azure storage service in Python
[For beginners] How to register a library created in Python in PyPI
I tried to implement PLSA in Python
[Introduction to Python] How to use class in Python?
How to access environment variables in Python
I tried to implement permutation in Python
How to dynamically define variables in Python
Using venv in Windows + Docker environment [Python]
How to do R chartr () in Python
How to convert Python to an exe file
[Itertools.permutations] How to put permutations in Python
I tried to implement PLSA in Python 2
How to implement nested serializer in drf-flex-fields
How to get a stacktrace in python
How to display multiplication table in python
How to extract polygon area in Python
How to check opencv version in python
I tried to implement ADALINE in Python
How to install Windows Subsystem For Linux
I tried to implement PPO in Python
How to switch python versions in cloud9
How to adjust image contrast in Python
How to use __slots__ in Python class
How to dynamically zero pad in Python
How to use "deque" for Python data
How to use regular expressions in Python
How to implement Scroll View in pythonista 1
How to display Hello world in python
How to use is and == in Python
How to write Ruby to_s in Python
How to install python3 with docker centos
How to make a container name a subdomain and make it accessible in Docker
How to use the C library in Python
Try to implement Oni Maitsuji Miserable in python
How to receive command line arguments in Python
[REAPER] How to play with Reascript in Python
How to clear tuples in a list (Python)
How to debug a Python program by remotely connecting to a Docker container in WSL2 environment with VS Code
How to generate permutations in Python and C ++
How to implement Rails helper-like functionality in Django
How to embed a variable in a python string
How to use Python Image Library in python3 series
How to create a JSON file in Python