Convert Python Code to Single Executable

We will be using Auto Py to EXE tool for building EXE out of Python code. This is a UI wrapper over PyInstaller, which is used in the backend.

Install Auto Py to EXE Tool

Open Command Prompt and enter the below line to install Auto Py to EXE tool.
 
pip install auto-py-to-exe

Creating Executable (EXE) from Python Code

There are two ways to build executable from python code:
  1. Creating EXE via Command Prompt 
  2. Creating EXE from PyCharm

Creating EXE via Command Prompt

1. Open Command Prompt and launch the Auto Py to EXE by entering the below line:

auto-py-to-exe

This will launch the Auto Py to EXE tool, as shown below.

2. Choose  the main Python file that you would like to build into EXE.

3. If "One Directory" option is selected, there will be multiple supporting files present parallel to the EXE. Change the selection from "One Directory" to "One File" if you would like to build a single executable file.

4. Click on Convert .PY to .EXE. This will generate the EXE out of the Python code. All done!

Creating EXE via PyCharm

We can integrate Auto Py to EXE tool to PyCharm, so that we can create EXE from PyCharm directly.
1. Open PyCharm and go to File -> Settings -> Tools -> External Tools. Click on the Add New Tool option.
Below are the settings to use to add Auto Py to EXE tool to PyCharm:
2. You can now right click the Python file and go to External Tools -> Auto Py to EXE

This will launch the Auto Py to EXE tool. Click "Convert .PY to EXE" to build the executable. All done!

No comments:

Feel free to leave a piece of your mind.

Powered by Blogger.