2.16. lib - pyinstaller¶
pyinstaller is a packaging module for python projects. It is most efficiently used with virtualenv where only the python packages needed for the project are packaged up (thereby creating a smaller .exe).
2.16.1. Installation¶
pip install pyinstaller
2.16.2. Usage¶
create a virtualenv and activate it
install necessary python packages for the project
complete the project
run pyinstaller
pyinstaller does not need to be locally installed within your project for it package up your project, however it does help to keep a stable working version locked with your project. If your global python path is setup (you are able to type
python
in your terminal), thenpyinstaller
should also work if it is installed. Normally pyinstaller will be in the Scripts folderrunning pyinstaller:
pyinstaller yourmodule.py --onefile
if everything goes well this will create 3 items:
build folder: contains compiled parts of your package and log files
dist folder: contains your single .exe file
.spec file: instructions for pyinstaller to create an executable
2.16.3. TroubleShooting¶
always check your package runs before compiling
build the project and see what the error log says when running the .exe it is usually an import error or version incompatability.
Fixing import error. Edit your spec file to include location of missing module, for example for pyqt5
...
datas=[('c:/users/username/projectvenv/Lib/site-packages/PyQt5/Qt/bin/*','PyQt5/Qt/bin')],
...
then compile your project via .spec file
pyinstaller project.spec
. If you dont have a spec file, create one viapyi-makespec project --onefile