Last modified: May 25, 2025 By Alexander Williams
How to Install Python from Source
Installing Python from source gives you the latest version and full control over the build process. This guide covers the steps for Linux, macOS, and Windows.
Table Of Contents
Prerequisites
Before installing Python from source, ensure you have these tools:
Linux/macOS: GCC, make, and development libraries.
Windows: Visual Studio or MinGW for compilation.
Check if GCC is installed:
gcc --version
gcc (Ubuntu 9.4.0-1ubuntu1~20.04) 9.4.0
Download Python Source Code
Get the latest Python source from the official website:
wget https://www.python.org/ftp/python/3.12.0/Python-3.12.0.tgz
Extract the downloaded file:
tar -xf Python-3.12.0.tgz
Configure the Build
Navigate to the Python directory and run configure
:
cd Python-3.12.0
./configure --enable-optimizations
The --enable-optimizations
flag improves performance.
Compile Python
Build Python using make:
make -j 8
The -j 8
speeds up compilation using 8 CPU cores.
Install Python
Install the compiled Python binaries:
sudo make altinstall
Note: Use altinstall
to avoid overwriting system Python.
Verify Installation
Check the installed Python version:
python3.12 --version
Python 3.12.0
Install pip
Python comes with ensurepip
to install pip:
python3.12 -m ensurepip --upgrade
For more details, see our guide on how to install pip for Python.
Create Virtual Environment
Use venv
to create isolated environments:
python3.12 -m venv myenv
Learn more about Python virtual environments.
Windows Installation
On Windows, use Visual Studio for compilation:
- Open "x64 Native Tools Command Prompt"
- Run
PCbuild\build.bat
For alternative methods, see how to install Python on Windows.
Conclusion
Installing Python from source gives you the latest features. Follow these steps for Linux, macOS, or Windows.