Python with WSL (Windows Subsystem for Linux)

WSL provides a virtualized instance of Linux running alongside the typical Windows environment, allowing users to access Linux commands without requiring a second computer, a dedicated virtual machine, or a dual-boot situation.

WSL2 is the recommended release of WSL. WSL2 requires Windows 11 or Windows 10 version 1903 or higher.

A very thorough video on the foundations of WSL can be found at Using Windows Subsystem for Linux v2 - YouTube

OIT provides these instructions as a general self-help guide. OIT Desktop Support does not provide technical support on Linux, Python, or the WSL platform.

Instructions

A. Install WSL and Ubuntu

  1. Open a command prompt with Administrator permissions by clicking on the start menu, typing “command” and then selecting “Run as administrator” from the right pane.

  2. Enter the command: wsl.exe --install

  3. WSL will install the required features as well as Ubuntu as the default Linux distribution.

  4. Restart your computer at this point.

  5. After restart, Ubuntu will automatically install.

  6. Ubuntu will prompt you to create a username and password. These credentials are separate from your UA myBama/Active Directory credentials. Please use a password manager to securely document your selected username and password.

Once Ubuntu is installed, it will appear as a start menu option for future use.

 

B. Run Python

  1. Python3 is generally automatically included in the Ubuntu distribution installed by default. Check that python3 is installed by running the command: python3 --version

  2. To update Python3 and install pip (if needed) run the command: sudo apt install python3 python3-pip

  3. You may need to install additional Python packages depending on your needs. Before installing additional packages, it is recommended to create a virtual environment (or multiple virtual environments) to meet your needs. Many tutorials exist on the web or actual python environment configuration and programming, and are beyond the scope of this article. The tutorial at Web development with Python on Windows | Microsoft Learn provided by Microsoft is particularly helpful in getting started with configuring Visual Studio Code to use WSL and creating virtual environments.