Skip to main content
This guide covers building CPython from source code for development purposes. Building from source allows you to test changes, debug issues, and contribute to CPython development.

Basic Build Process

1

Configure the build

From the top-level directory:
This prepares the build system for your platform.
2

Build CPython

This compiles the Python interpreter and standard library.
3

Test the build

This runs the test suite to verify your build.
4

Install (optional)

This installs Python as python3. For development, you typically don’t need to install.
The executable is called python.exe on macOS case-insensitive file systems and Cygwin; elsewhere it’s just python.

Development Builds

Debug Build

For development work, use a debug build with additional checks:
A debug build:
  • Enables assertions and extra debugging code
  • Includes reference count tracking
  • Adds memory debugging features
  • Makes debugging with gdb easier

Out-of-Tree Build

To keep your source directory clean, use an out-of-tree build:
If you’ve already built in the top-level directory, run make clean there first to avoid conflicts.

Build Options

Optimized Build

For performance testing or benchmarking:
This enables:
  • Profile Guided Optimization (PGO): Optimizes based on runtime profiling
  • Link Time Optimization (LTO): Cross-module optimization (on supported platforms)
Optimized builds take significantly longer due to the profiling step. Use them only when performance matters.

Common Configure Options

Profile Guided Optimization (PGO)

When you use --enable-optimizations or run make profile-opt, the build process:
1

Clean

Removes temporary files from previous builds.
2

Build instrumented interpreter

Creates an instrumented version with profiling code embedded.
3

Run training workload

Executes the test suite to collect profiling data. Output is suppressed during this step.
4

Build optimized interpreter

Builds the final interpreter using the profiling data for optimization.

Platform-Specific Builds

macOS Framework Build

macOS has special framework build options:
See Mac/README.rst for details on:
  • Framework builds
  • Universal builds
  • Code signing requirements

Windows

Windows uses a different build system:
See PCbuild/readme.txt for:
  • Visual Studio requirements
  • Build configurations
  • Creating Windows installers

Build Targets

Parallel Builds

Speed up compilation with parallel jobs:

Installing Multiple Versions

To install multiple Python versions using the same prefix:
1

Decide on primary version

Choose which version will be your “primary” Python (e.g., 3.15).
2

Install primary version

3

Install other versions with altinstall

make altinstall prevents overwriting the python3 symlink.

Troubleshooting

Some standard library modules require external libraries. The build will succeed but those modules will be unavailable. Check:
Install missing dependencies and rebuild.
Messages about skipped tests for optional features are normal:
Only worry about actual failures or tracebacks.
If you’re seeing weird behavior:
For system-wide installation:
For development, consider installing to a user directory:

Verifying Your Build

After building, verify it works:

Next Steps

Additional Resources