Last modified: May 26, 2025 By Alexander Williams
Install cx_Freeze for Python Easily
cx_Freeze is a tool to convert Python scripts into standalone executables. It works on Windows, macOS, and Linux. This guide will help you install it easily.
Prerequisites
Before installing cx_Freeze, ensure you have Python installed. If not, follow our guide on Install Python on Ubuntu in 5 Steps.
You also need pip, Python's package installer. It usually comes with Python. Check its version with:
# Check pip version
pip --version
# Output example
pip 22.3.1 from /usr/local/lib/python3.10/site-packages/pip (python 3.10)
Install cx_Freeze
Use pip
to install cx_Freeze. Run this command in your terminal:
# Install cx_Freeze
pip install cx_Freeze
This will download and install the latest version. For a specific version, use:
# Install specific version
pip install cx_Freeze==6.11.0
Verify Installation
Check if cx_Freeze installed correctly. Run:
# Verify installation
cxfreeze --version
# Output example
6.11.0
Create a Simple Executable
Let's create a simple Python script and convert it to an executable. Save this as hello.py:
# hello.py
print("Hello, cx_Freeze!")
Create a setup script named setup.py:
# setup.py
from cx_Freeze import setup, Executable
setup(
name="Hello",
version="0.1",
description="My Hello App",
executables=[Executable("hello.py")]
)
Now, build the executable:
# Build the executable
python setup.py build
This creates a build folder with your executable inside.
Advanced Configuration
cx_Freeze supports advanced options. You can include additional files or packages. Modify setup.py like this:
# Advanced setup.py
from cx_Freeze import setup, Executable
build_options = {
"packages": ["os"],
"excludes": ["tkinter"],
"include_files": ["data.txt"]
}
setup(
name="Hello",
version="0.1",
options={"build_exe": build_options},
executables=[Executable("hello.py")]
)
This includes the os
package and excludes tkinter
. It also adds data.txt to the build.
Common Issues
If you encounter errors, ensure your Python version is compatible. cx_Freeze works with Python 3.6+. For multiple Python versions, use Install Multiple Python Versions with pyenv.
Permission errors may occur on Linux. Use sudo
if needed:
# Install with sudo
sudo pip install cx_Freeze
For macOS, ensure you have Xcode tools installed. Check our guide on Install Python on macOS with Homebrew.
Conclusion
cx_Freeze is a powerful tool for creating Python executables. It's easy to install and use. Follow this guide to get started quickly.
For more Python tips, check our other tutorials. Happy coding!