Python: Make A Standalone Executable from Python script using PyInstaller

Run PyInstaller

  • Use standard python

Compile hello.py to hello.exe

pyinstaller hello.py

Compile into one standalone executable file

pyinstaller hello.py --onefile

Incorporate version file to executable file

pyinstaller hello.py --onefile --version-file=version.txt

Make icon of executable file

pyinstaller hello.py --onefile --version-file=version.txt -i icon.ico


If pyinstaller is not in $PATH environment variable, you may try the following command to import package directly.

python3 -m pyinstaller hello.py

or

python3 -m PyInstaller hello.py


Example:

pyinstaller -w -F -i molecule.ico -n OctaDist-2.3.beta-Win-x86-64 --version-file=version-2.3.beta.txt main.py


  • Use Anaconda

1. use python with importing Pyinstaller

/where/you/install/anaconda3/bin/python3.6 -m PyInstaller hello.py


2. If you install PyInstaller on local directory (in your home) using Anaconda's python, pyinstaller is installed in the hidden directory.

For example, /home/rangsiman/.local/bin/pyinstaller

Use the following command to make an executable file

/home/rangsiman/.local/bin/pyinstaller hello.py


Rangsiman Ketkaew