Fundamentals 12 min read

Choosing the Right Python Environment on WSL: venv vs conda vs uv

This guide compares Python virtual‑environment tools—pip + venv, Miniconda, and the new uv—detailing installation steps, performance differences, use‑case recommendations, and practical commands for setting up a consistent development environment on Ubuntu WSL.

Ubuntu
Ubuntu
Ubuntu
Choosing the Right Python Environment on WSL: venv vs conda vs uv

Why Python works well in WSL

Installing dependencies : Windows often fails with missing headers, while WSL can resolve them with apt install.

Path handling : Windows uses backslashes and spaces; WSL uses clean forward slashes.

Script execution : Windows file‑association is messy; WSL runs scripts directly with python3 file.py.

Multiple versions : Windows requires manual PATH tweaks; WSL can switch versions easily with pyenv or package managers.

Production consistency : Windows differs from Linux servers; WSL is almost identical.

NumPy/Pandas performance : Faster on Linux‑compiled WSL.

Step 1: Install Python

Ubuntu comes with Python

# Ubuntu 24.04 includes Python 3.12+
python3 --version
# Install pip, venv, dev headers
sudo apt install -y python3-pip python3-venv python3-dev
# Upgrade pip
python3 -m pip install --upgrade pip
# Verify versions
python3 --version && pip --version

Important rule: never sudo pip install

# ❌ Wrong: pollutes system Python
sudo pip install requests
# ✅ Correct: use a virtual environment
python3 -m venv .venv
source .venv/bin/activate
pip install requests
deactivate

Three package managers comparison

Overview

pip + venv – official standard, lightweight, suitable for small projects and learning (⭐️⭐️⭐️⭐️).

uv – Rust‑based, extremely fast (10‑100×), auto‑creates virtual env, ideal for new projects (⭐️⭐️⭐️⭐️⭐️).

Miniconda – data‑science ecosystem, binary packages, easy multi‑Python switching, larger install size (⭐️⭐️⭐️⭐️).

Detailed comparison

pip + venv:
┌─────────────────────────────┐
│ Advantages                   │
│ • Official Python solution   │
│ • No extra installation      │
│ • Lightweight, per‑project   │
│ Disadvantages                │
│ • Slower (pip download)      │
│ • No Python version manager  │
│ • Large projects may stall    │
└─────────────────────────────┘

uv:
┌─────────────────────────────┐
│ Advantages                   │
│ • Extremely fast (10‑100×)   │
│ • Auto‑creates/manages env    │
│ • One‑command project init    │
│ • Built‑in Python version mgmt│
│ • Low resource usage (Rust)   │
│ Disadvantages                │
│ • Newer ecosystem            │
│ • Some edge‑case compatibility│
└─────────────────────────────┘

Miniconda / conda:
┌─────────────────────────────┐
│ Advantages                   │
│ • Full data‑science stack    │
│ • Binary packages (no compile)│
│ • Manages non‑Python packages│
│ • Easy multi‑Python switching│
│ Disadvantages                │
│ • Large installer (~500 MB) │
│ • Slower startup             │
│ • Possible pip conflicts     │
│ • License restrictions      │
└─────────────────────────────┘

Solution 1: uv – preferred for new projects

Installation

# One‑line install (official script)
curl -LsSf https://astral.sh/uv/install.sh | sh
# Reload shell or restart terminal
source ~/.bashrc
uv --version  # e.g., uv 0.x.x

Quick start

# Initialise a new project (creates pyproject.toml + env)
uv init my-project && cd my-project
# Add dependencies (installed into the env)
uv add requests fastapi uvicorn sqlalchemy
# Run the code
uv run main.py
# Add development‑only dependencies
uv add --dev pytest black ruff
# Run tests
uv run pytest
# List installed packages
uv pip list
# Export requirements for compatibility
uv pip freeze > requirements.txt
# Install from a requirements file
uv pip install -r requirements.txt
# Install a specific Python version
uv python install 3.11
uv run --python 3.11 main.py

Project structure example

my-project/
├── .venv/          # managed by uv
├── pyproject.toml  # project config & dependencies
├── main.py
└── README.md
[project]
name = "my-project"
version = "0.1.0"
requires-python = ">=3.10"
dependencies = [
    "requests>=2.31.0",
    "fastapi>=0.104.0",
    "uvicorn[standard]>=0.24.0",
]

Solution 2: pip + venv – traditional reliable

Create and use a virtual environment

# Create project directory
mkdir -p ~/projects/myapp && cd ~/projects/myapp
# Create virtual environment
python3 -m venv .venv
# Activate it
source .venv/bin/activate
# Upgrade packaging tools
pip install --upgrade pip setuptools wheel
# Install dependencies
pip install flask pandas numpy
# List packages
pip list
# Exit the environment
deactivate

Batch dependency management

# Export all packages
pip freeze > requirements.txt
# Install from file
pip install -r requirements.txt
# Export only direct dependencies
pip freeze --exclude-editable > requirements.txt
# Use pip-tools for precise control
pip install pip-tools
pip-compile requirements.in   # generates requirements.txt
pip-sync requirements.txt    # installs exactly

Auto‑activate virtual environment (optional)

# Install autoenv
pip install autoenv
# Add to bashrc
echo 'source $(python3 -m autoenv site)' >> ~/.bashrc
# Create .env in project to auto‑activate
echo 'source .venv/bin/activate' > ~/projects/myapp/.env
# Next cd into the directory will auto‑activate

Solution 3: Miniconda – data‑science choice

Install Miniconda

# Download latest Miniconda installer
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
# Run installer (accept defaults)
bash Miniconda3-latest-Linux-x86_64.sh
# Reload shell
source ~/.bashrc
conda --version

Common conda commands

# Create environment with specific Python version
conda create -n datascience python=3.11
conda activate datascience
# Install data‑science packages (conda handles binaries)
conda install numpy pandas matplotlib scikit-learn jupyter seaborn plotly
# Install packages not in conda via pip
pip install some-special-package
# List environments
conda env list
# Export / import environment
conda export > environment.yml
conda env create -f environment.yml
# Remove an environment
conda remove -n old-env --all
# Clean cache
conda clean --all

Jupyter Notebook setup

# Install Jupyter
conda install jupyter ipykernel
# Launch Lab (accessible from Windows browser)
jupyter lab --ip=0.0.0.0 --port=8888 --no-browser
# Open http://localhost:8888 and copy the token if prompted

Common Python packages quick reference

Web development

pip install fastapi uvicorn   # modern API framework
pip install flask            # classic lightweight framework
pip install django           # full‑stack framework
pip install httpie           # API testing tool (curl alternative)

Data science

pip install numpy pandas matplotlib
pip install seaborn plotly
pip install scikit-learn
pip install jupyterlab
pip install openpyxl xlrd

Development tools

pip install pytest pytest-cov
pip install black isort ruff
pip install mypy
pip install httpx
pip install rich
pip install python-dotenv

VS Code + Python + Remote‑WSL configuration

Install the following VS Code extensions: Python (ms-python.python), Pylance (ms-python.vscode-pylance), Black Formatter (ms-python.black-formatter), Jupyter (ms-toolsai.jupyter).

If VS Code does not auto‑detect the virtual environment, select the interpreter via “Python: Select Interpreter” and choose .venv/bin/python or the conda python path.

{
    "python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python",
    "python.formatting.provider": "black",
    "python.linting.enabled": true,
    "python.testing.pytestEnabled": true,
    "[python]": {
        "editor.defaultFormatter": "ms-python.black-formatter",
        "editor.formatOnSave": true,
        "editor.codeActionsOnSave": {
            "source.organizeImports": "explicit"
        }
    }
}
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

PythonVS CodeWSLvenvCondauv
Ubuntu
Written by

Ubuntu

Focused on Ubuntu/Linux tech sharing, offering the latest news, practical tools, beginner tutorials, and problem solutions. Connecting open-source enthusiasts to build a Linux learning community. Join our QQ group or channel for discussion!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.