Basic Build Process
1
Configure the build
From the top-level directory:This prepares the build system for your platform.
2
Build CPython
3
Test the build
4
Install (optional)
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:- 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:Build Options
Optimized Build
For performance testing or benchmarking:- 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:- Framework builds
- Universal builds
- Code signing requirements
Windows
Windows uses a different build system:- 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
Build fails with missing dependencies
Build fails with missing dependencies
Some standard library modules require external libraries. The build will succeed but those modules will be unavailable. Check:Install missing dependencies and rebuild.
make test fails on optional modules
make test fails on optional modules
Messages about skipped tests for optional features are normal:Only worry about actual failures or tracebacks.
Stale build artifacts
Stale build artifacts
If you’re seeing weird behavior:
Permission errors during install
Permission errors during install
For system-wide installation:For development, consider installing to a user directory:
Verifying Your Build
After building, verify it works:Next Steps
Additional Resources
- CPython Developer Guide
- Special Build Types (Misc/SpecialBuilds.txt)
- GitHub Actions CI
- Azure Pipelines CI
