If you’re a Python developer using Windows 11, you’ve probably heard of the Windows Subsystem for Linux (WSL) — a feature that lets you run a full Linux environment directly inside Windows, without the need for a virtual machine or dual boot setup. WSL makes it possible to use Linux tools, package managers, and workflows while still enjoying the convenience of Windows applications.
Setting up Python on WSL gives you the best of both worlds: you get the stability and simplicity of Linux for development, plus the familiar interface and performance of Windows. In this guide, we’ll show you exactly how to install and configure Python for development on WSL, including how to connect it with VS Code, install dependencies, and manage virtual environments properly.
Why Use Python on WSL?
Before diving into the setup steps, let’s quickly understand why using WSL for Python development is such a game-changer.
- Cross-Platform Compatibility: Most Python libraries and frameworks (like Django, Flask, NumPy, and TensorFlow) are originally built for Linux, so running them in WSL ensures better compatibility and fewer dependency issues.
- Access to Linux Tools: You can use commands like
apt,pip, andvenvjust like on native Linux. - Seamless Integration with VS Code: WSL works beautifully with Visual Studio Code, allowing you to edit files in Windows while executing them in Linux.
- Faster Builds: Many Python modules compile faster in WSL compared to Windows-native builds, especially those requiring
gccormake. - Lightweight Environment: Unlike a full virtual machine, WSL uses minimal resources and integrates directly with your Windows filesystem.
Step 1: Install WSL on Windows 11
First, you need to install the Windows Subsystem for Linux. Windows 11 makes this process incredibly easy.
- Open Command Prompt or PowerShell as Administrator.
- Run the following command:
wsl --install - This will automatically enable the required features, download the latest Ubuntu distribution, and set it up.
- Once done, restart your PC when prompted.
After reboot, open the Ubuntu app from the Start menu — this is your Linux environment inside Windows.
Tip: If you prefer a different distribution like Debian or Kali, you can list available ones with:
wsl --list --online
Then install your choice, e.g.:
wsl --install -d debian
Step 2: Update Package Manager
Before installing Python, make sure your Linux environment is up to date.
sudo apt update && sudo apt upgrade -y
This ensures that all existing packages and dependencies are current, avoiding installation conflicts later on.
Step 3: Install Python in WSL
Most WSL distributions come with Python preinstalled, but it’s always a good idea to check and install the latest version manually.
- To check if Python is installed:
python3 --version - If it’s not available or outdated, install it using:
sudo apt install python3 python3-pip -y - Once installed, verify again:
python3 --version pip3 --version
You should now see the current Python and pip versions displayed on your terminal.
Step 4: Set Up a Virtual Environment
Using a virtual environment is one of the best practices for Python development. It keeps your project dependencies isolated and avoids version conflicts.
- Install the
venvmodule (if it’s not already included):sudo apt install python3-venv -y - Create a new project folder:
mkdir my-python-project && cd my-python-project - Create a virtual environment:
python3 -m venv venv - Activate it:
source venv/bin/activate
Once activated, you’ll see (venv) at the beginning of your terminal prompt — this means your environment is ready.
Step 5: Connect WSL Python to VS Code
If you prefer coding in Visual Studio Code, integrating it with WSL is simple and powerful.
- Install Visual Studio Code on Windows if you haven’t already.
- Open VS Code and install the Remote – WSL extension from the Extensions tab.
- In VS Code, press Ctrl + Shift + P, then select:
Remote-WSL: New WSL Window - Navigate to your project folder:
cd ~/my-python-project - Open VS Code from within WSL:
code .
VS Code will automatically connect to your WSL environment, allowing you to edit files and run Python directly from Linux without leaving your editor.
Step 6: Install Common Python Tools and Libraries
Once your Python setup is ready, you can start installing essential packages. For example:
pip install requests flask django numpy pandas matplotlib
To make development easier, you can also install common developer tools like:
sudo apt install build-essential git curl -y
These packages ensure compatibility with Python modules that need native extensions or compilation.
Step 7: Configure Python Path (Optional)
If you’re working across both Windows and WSL, sometimes you may need to specify which Python interpreter to use.
In VS Code, you can do this easily:
- Press Ctrl + Shift + P, type:
Python: Select Interpreter - Choose the one that corresponds to your WSL environment (it usually looks like
/usr/bin/python3).
This helps VS Code recognize your correct Python environment for linting, debugging, and running scripts.
Step 8: Test Your Setup
Now let’s confirm everything works. Run a simple Python script:
python3
Then type:
print("Hello from WSL!")
If you see the output successfully, congratulations — your Python setup on WSL is fully functional.
Troubleshooting Common Issues
Here are some common problems you might encounter — and how to fix them:
1. “python3: command not found”
This means Python isn’t installed. Run:
sudo apt install python3 -y
2. pip Not Recognized
If pip doesn’t work, reinstall it manually:
sudo apt install python3-pip -y
3. VS Code Doesn’t Detect Python
Make sure the VS Code Python extension and Remote – WSL extensions are both installed. Restart VS Code if needed.
4. Virtual Environment Won’t Activate
Ensure you’re using Bash or Zsh. If it still fails, re-run:
source venv/bin/activate
Wrapping Up
Setting up Python for development on WSL gives you a powerful hybrid workflow — Linux’s developer-friendly tools combined with Windows’s usability. Once installed, you can use Python commands, install packages, and develop applications in a true Linux environment — all without leaving your Windows desktop.
Whether you’re building web apps, data analysis tools, or machine learning projects, using Python with WSL ensures smoother performance, faster builds, and maximum compatibility with open-source tools.
Now that your environment is ready, you can start coding, exploring frameworks like Django or Flask, or automating tasks right from your WSL terminal — all powered by Python.