Skip to content

Instantly share code, notes, and snippets.

@minhphong306
Created November 5, 2025 06:07
Show Gist options
  • Select an option

  • Save minhphong306/ded38fa604bf017791312f7b2b674015 to your computer and use it in GitHub Desktop.

Select an option

Save minhphong306/ded38fa604bf017791312f7b2b674015 to your computer and use it in GitHub Desktop.
guide.md

There are several ways to compile Python code to an executable (.exe) file. Here are the most popular methods:

PyInstaller (Most Popular)

PyInstaller is the most widely used tool and works well for most projects:

# Install
pip install pyinstaller

# Basic usage - creates a folder with dependencies
pyinstaller your_script.py

# Create a single .exe file
pyinstaller --onefile your_script.py

# Add an icon
pyinstaller --onefile --icon=myicon.ico your_script.py

# Hide the console window (for GUI apps)
pyinstaller --onefile --noconsole your_script.py

Auto-py-to-exe (GUI for PyInstaller)

If you prefer a graphical interface:

pip install auto-py-to-exe
auto-py-to-exe

This opens a browser-based GUI where you can configure all options visually.

cx_Freeze

Another solid option that's cross-platform:

pip install cx_Freeze

# Create a setup.py file, then run:
python setup.py build

Nuitka

Compiles Python to C++ first, resulting in faster executables:

pip install nuitka
python -m nuitka --onefile your_script.py

Things to Keep in Mind

  • The .exe will only work on Windows (for cross-platform, look into PyInstaller for each OS)
  • The resulting file can be large (includes Python interpreter + dependencies)
  • Antivirus software sometimes flags these files as suspicious
  • Test thoroughly - not all Python packages work perfectly when compiled

PyInstaller with --onefile is usually the best starting point for most projects. Would you like help with a specific tool or running into any particular issues?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment