How to Easily Convert a Python Script to an Executable File (.exe)

 Although running a Python script using the terminal or your favorite text editor is straightforward, there are some situations in which you will prefer to hide all the code written in the script (.py) inside an executable file (.exe).

Making an Executable file with auto-py-to-exe

Installing with pip

pip install auto-py-to-exe

Running auto-py-to-exe

auto-py-to-exe

Steps to create an executable file

Step 1: Add the script location

Feel free to choose any script you want. However, if your script needs to read a path make sure that you use absolute paths since relative paths won’t behave as you might expect with executable files. If necessary, include the following line of code below to know where the executable file is located and make the necessary changes to your script so you read/export files on the right directory.
application_path = os.path.dirname(sys.executable)

Step 2: Choosing “One Directory” or “One File”

Step 3. Choosing “Console Based” or “Window Based”

Step 4: Advanced options (e.g., output directory, additional imports)
Image by author

Step 5: Convert the file

Image by author

Making an Executable file with PyInstaller

  • Step 1: Open up a terminal and run pip install pyinstaller

Post a Comment

Previous Post Next Post