Text of devguide.python.org › getting-started › setup-building as Styx crawled it on Nov 18, 2026. The page may have changed since. Only its words are kept, without pictures or layout, and only the first part of a long page.

Open the live page

Setup and building

Skip to content Back to top View this page Edit this page Setup and building ¶ These instructions cover how to get a working copy of the source code and a compiled version of the CPython interpreter (CPython is the version of Python available from https://www.python.org/ ). It also gives an overview of the directory structure of the CPython source code. Alternatively, if you have Docker installed you might want to use our official images .

These contain the latest releases of several Python versions, along with Git head, and are provided for development and testing purposes only. See also The Quick reference gives brief summary of the process from installing Git to submitting a pull request. Install Git ¶ CPython is developed using Git for version control. The Git command line program is named git ; this is also used to refer to Git itself. Git is easily available for all common operating systems.

Install As the CPython repo is hosted on GitHub, please refer to either the GitHub setup instructions or the Git project instructions for step-by-step installation directions. You may also want to consider a graphical client such as TortoiseGit or GitHub Desktop . Configure Configure your name and email and create an SSH key as this will allow you to interact with GitHub without typing a username and password each time you execute a command, such as git pull , git push , or git fetch .

On Windows, you should also enable autocrlf . Get the source code ¶ The CPython repo is hosted on GitHub. To get a copy of the source code you should fork the Python repository on GitHub , create a local clone of your personal fork, and configure the remotes . You will only need to execute these steps once per machine: Go to https://github.com/python/cpython . Press Fork on the top right. When asked where to fork the repository, choose to fork it to your username.

Your fork will be created at https://github.com/ <username> /cpython . Clone your GitHub fork (replace <username> with your username): $ git clone git@github.com:<username>/cpython.git (You can use both SSH-based or HTTPS-based URLs.) Add an upstream remote, then configure git to pull main from upstream and always push to origin : $ cd cpython $ git remote add upstream https://github.com/python/cpython $ git config --local branch.main.remote upstream $ git remote set-url --push upstream git@github.com:<your-username>/cpython.git Verify that your setup is correct: $ git remote -v origin git@github.com:<your-username>/cpython.git (fetch) origin git@github.com:<your-username>/cpython.git (push) upstream https://github.com/python/cpython (fetch) upstream git@github.com:<your-username>/cpython.git (push) $ git config branch.main.remote upstream For more information about these commands see Git Bootcamp and Cheat Sheet .

If you did everything correctly, you should now have a copy of the code in the cpython directory and two remotes that refer to your own GitHub fork ( origin ) and the official CPython repository ( upstream ). If you want a working copy of an already-released version of Python, that is, a version in maintenance mode , you can checkout a release branch. For instance, to checkout a working copy of Python 3.13, do git switch 3.13 .

You will need to re-compile CPython when you do such an update. Do note that CPython will notice that it is being run from a working copy. This means that if you edit CPython’s source code in your working copy, changes to Python code will be picked up by the interpreter for immediate use and testing. (If you change C code, you will need to recompile the affected files as described below.) Changes for the documentation can be made from the same repository; see Getting started .

Install pre-commit as a Git hook ¶ To make sure your code is linted correctly, we recommend setting up pre-commit as a Git hook: $ pre-commit install --allow-missing-config pre-commit installed at .git/hooks/pre-commit Now pre-commit will run automatically on git commit . Compile and build ¶ CPython provides several compilation flags which help with debugging various things. While all of the known flags can be found in the Misc/SpecialBuilds.txt file, the most critical one is the Py_DEBUG flag which creates what is known as a “pydebug” build.

This flag turns on various extra sanity checks which help catch common issues. The use of the flag is so common that turning on the flag is a basic compile option. You should always develop under a pydebug build of CPython (the only instance of when you shouldn’t is if you are taking performance measurements). Even when working only on pure Python code the pydebug build provides several useful checks that one should not skip.

See also The effects of various configure and build flags are documented in the Python configure docs . Unix ¶ The core CPython interpreter only needs a C compiler to be built, however, some of the extension modules will need development headers for additional libraries (such as the zlib library for compression). Depending on what you intend to work on, you might need to install these additional requirements so that the compiled interpreter supports the desired features.

If you want to install these optional dependencies, consult the Install dependencies section below. If you don’t need to install them, the basic steps for building Python for development is to configure it and then compile it. Configuration is typically: $ ./configure --with-pydebug More flags are available to configure , but this is the minimum you should do to get a pydebug build of CPython. Tip To speed up repeated configure runs, use --config-cache (equivalent to --cache-file=config.cache , short: -C ): $ ./configure --config-cache --with-pydebug This caches results in a config.cache file.

If you switch compilers or significantly change your build environment, delete config.cache before re-running configure . Note You might need to run make clean before or after re-running configure in a particular build directory. Once configure is done, you can then compile CPython with: $ make -s -j $( nproc ) This will build CPython with only warnings and errors being printed to stderr. The -j argument means that make will concurrently run tasks, limiting the number of parallel jobs to the number of CPU cores in your computer.

You can adjust the number passed to the -j flag to change the limit on parallel jobs, which can trade RAM usage versus compilation time. At the end of the build you should see a success message, followed by a list of extension modules that haven’t been built because their dependencies were missing: The necessary bits to build these optional modules were not found: _gdbm To find the necessary bits, look in configure.ac and config.log.

Checked 106 modules (31 built-in, 74 shared, 0 n/a on macosx-13.4-arm64, 0 disabled, 1 missing, 0 failed on import) If the build failed and you are using a C89 or C99-compliant compiler, please open a bug report on the issue tracker . If you decide to Install dependencies , you will need to re-run both configure and make . Once CPython is done building you will then have a working build that can be run in-place; ./python on most machines (and what is used in all examples), ./python.exe wherever a case-insensitive filesystem is used (for example, on macOS by default), in order to avoid conflicts with the Python directory.

There is normally no need to install your built copy of Python! The interpreter will realize where it is being run from and thus use the files found in the working copy. If you are worried you might accidentally install your working copy build, you can add --prefix=/tmp/python to the configuration step. When running from your working directory, it is best to avoid using the --enable-shared flag to configure ; unless you are very careful, you may accidentally run with code from an older, installed shared Python library rather than from the interpreter you just built.

Clang ¶ If you are using clang to bu

The rest of this page is on the live site.