For those who want to quickly EXE the Python code used in Linux on Docker to pass it to others.
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.
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.
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