Sunday, November 10, 2019

How to convert your Python script into an executable file (from .py to .exe)

1. pip install pyinstaller
2. Go to the folder which contains your python script (.py)... e.g. C:\user\Tim\
3. pyinstaller.exe --onefile --icon=sun_icon.ico python_script.py --noconsole

  • icon (*.ico) file should be in the same folder as your python script
  • --noconsole will eliminate the black screen that appears on running the exe file
  • "--hidden-import=modulename" will ensure that python also includes modules (that tend to be hidden) into the exe file (not guaranteed to work)
  • "-v" for verbose/detailed log

4. Go into the "dist" subfolder i.e. C:\user\Tim\dist\
5. Run the .exe file
Note: If the file appears to be stuck in a black screen, ensure any related images are also copied to the "dist" folder where the .exe file is located.

No comments:

Post a Comment

Popular Posts