Working with Python on Debian via Windows Subsystem for Linux (WSL)

Working with Python on Debian via WSL: A Detailed Guide

Table of Contents

Installing WSL for Debian

If the Microsoft Store is not an option, you can manually download a Debian .appxbundle file from a trusted source. After clicking on the file, it will install and ask for a UNIX username and password.

Accessing Windows Files in WSL

You can navigate to your Windows files within WSL by going to the /mnt/ directory. For example, to access the C drive:

cd /mnt/c/

Python Installation Options on WSL

For Python installation, you have two primary routes:

  • Basic Python: Use apt to install Python and pip.
    sudo apt update
    sudo apt install python3 python3-pip
  • Miniconda: Download the installer script and follow the installation prompts.
    bash Miniconda3-latest-Linux-x86_64.sh

Setting PYTHONPATH

If you have Python modules in a custom directory, you can add that directory to your PYTHONPATH using the following commands:

  • Temporarily (current session only):
    export PYTHONPATH=$PYTHONPATH:/path/to/custom/directory
  • Permanently: Add the export command to your .bashrc file.
    echo 'export PYTHONPATH=$PYTHONPATH:/path/to/custom/directory' >> ~/.bashrc
    source ~/.bashrc

Handling Matplotlib Installation Warning

Upon installing Matplotlib, you may encounter a warning indicating that certain scripts are not in your PATH. To add them:

  • Temporarily:
    export PATH=$PATH:/path/to/script/directory
  • Permanently: Add the path to your .bashrc.
    echo 'export PATH=$PATH:/path/to/script/directory' >> ~/.bashrc
    source ~/.bashrc

Comments