Skip to Content
DocsDevelopmentPython Development

Python Development Environment

Ubuntu 26.04 ships Python 3.14 by default (3.14.3 in the 26.04.1 images). This article covers how to set up a complete Python development environment with multi-version and virtual environment management.

System Python

Check the system Python version:

python3 --version

Install essential development packages:

sudo apt update sudo apt install python3-pip python3-venv python3-dev build-essential -y
Warning

Ubuntu 26.04 follows PEP 668: the system Python is marked “externally managed”, so you cannot pip install into the system environment directly — doing so raises an externally-managed-environment error. Always install inside a virtual environment (venv/conda), or use pipx for standalone CLI tools.

Using Python 3.14 and Other Versions

By default python3 points to Python 3.14 (3.14.3 in the 26.04.1 images). Check the current version:

python3 --version # Python 3.14.3

If you need an older version such as 3.13 or 3.12 (for example, because a third-party package does not support 3.14 yet), install it with the deadsnakes PPA or pyenv; do not replace the system python3, as that can break system tooling.

If you need an older or newer version not yet in the repository, use the deadsnakes PPA:

sudo add-apt-repository ppa:deadsnakes/ppa sudo apt update # For example, install 3.12 sudo apt install python3.12 python3.12-venv -y python3.12 --version
Note

Installing multiple python3.x versions does not change which version python3 points to. When you need to switch global/project versions flexibly, use pyenv (covered below).

Create Virtual Environments with venv

venv is Python’s built-in virtual environment tool, recommended for project-level dependency isolation:

# Create a virtual environment python3 -m venv myproject-env # Activate the virtual environment source myproject-env/bin/activate # Your prompt will now show (myproject-env) # Install dependencies pip install requests flask # Export dependencies pip freeze > requirements.txt # Install from a file pip install -r requirements.txt # Deactivate the virtual environment deactivate

pip Package Management

Basic Usage

# Install a package pip install package-name # Install a specific version pip install package-name==1.2.3 # Upgrade a package pip install --upgrade package-name # Uninstall a package pip uninstall package-name # List installed packages pip list # Find outdated packages pip list --outdated

Configure China Mirror Sources

When using pip in mainland China, configuring a mirror source is recommended for faster downloads:

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

Or manually create ~/.pip/pip.conf:

[global] index-url = https://pypi.tuna.tsinghua.edu.cn/simple trusted-host = pypi.tuna.tsinghua.edu.cn

Common mirror sources:

  • Tsinghua: https://pypi.tuna.tsinghua.edu.cn/simple
  • Aliyun: https://mirrors.aliyun.com/pypi/simple/
  • USTC: https://pypi.mirrors.ustc.edu.cn/simple/

pyenv Multi-Version Management

pyenv lets you install and switch between multiple Python versions on the same machine:

Install Dependencies

sudo apt install -y make build-essential libssl-dev zlib1g-dev \ libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \ libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev \ libffi-dev liblzma-dev

Install pyenv

curl https://pyenv.run | bash

Add the following to the end of ~/.bashrc (or ~/.zshrc):

export PYENV_ROOT="$HOME/.pyenv" export PATH="$PYENV_ROOT/bin:$PATH" eval "$(pyenv init -)" eval "$(pyenv virtualenv-init -)"

Apply the configuration:

source ~/.bashrc

Using pyenv

# List installable versions pyenv install --list | grep "^ 3\." # Install a specific version pyenv install 3.13 pyenv install 3.14 # Set the global version (3.14 recommended) pyenv global 3.14 # Set a local version for a project cd /path/to/project pyenv local 3.14 # List installed versions pyenv versions

Conda / Miniconda

Conda is a cross-platform package and environment management tool widely used in data science:

Install Miniconda

mkdir -p ~/miniconda3 wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda3/miniconda.sh bash ~/miniconda3/miniconda.sh -b -u -p ~/miniconda3 rm ~/miniconda3/miniconda.sh

Initialize the shell:

~/miniconda3/bin/conda init bash source ~/.bashrc

Configure China Mirror

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main conda config --set show_channel_urls yes

Using Conda

# Create an environment conda create -n myenv python=3.14 # Activate the environment conda activate myenv # Install packages conda install numpy pandas matplotlib # Export an environment conda env export > environment.yml # Create an environment from file conda env create -f environment.yml # List all environments conda env list # Remove an environment conda env remove -n myenv # Deactivate conda deactivate

uv: Next-Generation Package Manager

uv is a blazing-fast Python package manager written in Rust, compatible with pip:

# Install uv curl -LsSf https://astral.sh/uv/install.sh | sh # Use uv as a pip replacement uv pip install requests uv pip install -r requirements.txt # Create a virtual environment uv venv myenv source myenv/bin/activate # Manage projects with uv uv init myproject cd myproject uv add flask sqlalchemy uv run python app.py
myproject/ ├── pyproject.toml # Project configuration (recommended) ├── requirements.txt # Dependency list ├── src/ │ └── myproject/ │ ├── __init__.py │ └── main.py ├── tests/ │ └── test_main.py ├── .gitignore └── README.md

Choose your tools wisely to efficiently manage your Python development environment. For simple projects, venv + pip is recommended. For data science projects, Conda is the way to go. For speed, give uv a try.

Last updated on