Learn Before
Creating an executable using PyInstaller
If you're looking to use PyInstaller to create an executable, navigate to the folder where your relevant Python file(s) are located. Then, run the following command:
pyinstaller myscript.py
PyInstaller will then do a few things. It will generate a myscript.spec file in the same folder as your script. This spec file is actually a Python program itself, and PyInstaller simply runs the script contained in the myscript.spec file to create the executable. The spec file contains many options for how PyInstaller will generate your exe, which can actually be modified (but usually this is not necessary).
Next, PyInstaller creates a build folder and adds some log files to it. It then creates a dist folder where it writes the executable. This folder will contain dependency files, many of them .dll files, if the --onefile setting was not set. If the --onefile setting was set, there will just be an executable file which you can run from anywhere and distribute to anyone.
pyinstaller --onefile myscript.py
There are many other options PyInstaller gives you when creating the executable, including ways to exclude/include specific binary files. This is useful if you want to remove files that are from packages irrelevant to the final build of your project. For example, debugging packages could be excluded from the build to keep the file size more manageable. For more information on PyInstaller's command options, see the documentation.
0
1
Tags
Python Programming Language
Data Science