Use PyInstaller to convert the python to.exe

  • 2020-06-01 10:03:22
  • OfStack


Recently I have been using program a lot, but every time I use it on a different computer, I want to be able to publish the Python script as an executable running off the Python platform, such as a single exe. PyInstalle meets the requirements.

PyInstaller itself is not part of the Python package. Configure the python environment before installing pyinstaller.

Install pyinstaller

Download pyinstaller

Unzip to F:\ PyInstaller-2.1 (optional) (download the latest version from the official website)

Install pywin32

pywin32-217. win32-py2.7.exe: click to download

Install pyinstaller

1. Enter cmd

cd F:\PyInstaller-2.1

python --console --onefile

If prompted:

Usage: python [opts] [  ... ] | error: Requires at least one scriptname file or exactly one .spec-file

The installation is complete.

The test package

1. Put the files in the pyinstaller-2.1 folder in the current directory

cd F:\PyInstaller-2.1

python --console --onefile

2. One test folder will be generated after the successful execution of the command. Under this folder will be a folder named dist, which has the converted test.exe

3. The exe compiled above can run normally, but it has a black console. Recompile below, add the windowed and icon, and cancel the console

python -w --onefile --icon="my.ico"

my.ico is the custom icon file you want to add to it.


Related articles: