Install Python 3.9.1 on WSL

Raymond Tang Raymond Tang 0 29516 23.35 index 1/8/2022

This article summarizes the steps to install Python 3.9.1 on Windows Subsystem for Linux Debian distro. You can also apply them to other similar distros.

Installation steps

Run the following commands in your WSL terminal.

  1. Update package lists
sudo apt update
  1. Install dependent libraries
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev curl libbz2-dev
  1. Download Python binary package
wget https://www.python.org/ftp/python/3.9.1/Python-3.9.1.tgz
  1. Unzip the package
tar -xzf Python-3.9.1.tgz
  1. Execute configure script
cd Python-3.9.1
./configure --enable-optimizations
  1. Build Python 3.9
make -j 2
  1. Install Python 3.9
sudo make install

Verify the installation

Run the following command to install Python 3.9:

$ python3.9Python 3.9.1 (default, Jan  8 2022, 14:44:10)[GCC 6.3.0 20170516] on linuxType "help", "copyright", "credits" or "license" for more information.

Make Python 3.9 the default

If you want to make Python 3.9 the default python program, you can follow these steps:

  1. Change ~/.bashrc file to add the following line:
alias python='/usr/local/bin/python3.9'
  1. And then run the following command to make it effective:
source ~/.bashrc

You can verify it using python command directly:

python --version
Python 3.9.1

References

python wsl

Join the Discussion

View or add your thoughts below

Comments