In this post, I’ve outlined the steps for installing specific versions of Python on WSL in an easy-to-follow manner.
1. Install Windows Subsystem for Linux and Install Distro
In the Run dialog box, type optionalfeatures and press Enter. A window displaying Windows features will appear. Select ‘Windows Subsystem for Linux‘ from the list, proceed with the installation, and restart the system once the installation is complete.
Once the system is rebooted, in the command prompt, type
wsl.exe –list –online
which will list the available distros. From there, I will select the Ubuntu install.
wsl.exe –install Ubuntu
Once the installation is is finished, you’ll need to define the user name and password.
Anytime you can start the WSL system in the command prompt by typing wsl.exe in the command prompt.
[Resetting the WSL root password]
If you want to reset the password, you will need to start the WSL with the following command:
wsl.exe -u root
2. Install Required package for Python
Since we’re going to install python by compiling source files, we’d need to install some dependencies packages like compiler and openssl. First update, the respository and links.
sudo apt upgrade
Install Compilers and packages.
sudo apt-get install libssl-dev openssl make gcc
3. Python Installation
Download the python and extract the files.
tar xzvf Python-3.8.9.tgz
Now we will have a make file with the configure command which checks system configuration and sets up the build environment accordingly. The process takes some time, so be patient.
Here, we got the Make file, so now compile the source code and install binaries to the system with the following command.
sudo make install
4. Install Pip (Optional)
pip is an essential tool for Python development as it simplifies the process of managing external libraries and dependencies, making it easier to work with third-party packages and extend the capabilities of your Python projects. You can install it by:
sudo apt install python3-pip