Raymond Raymond

Install Python 3.9.1 on WSL

event 2022-01-08 visibility 25,361 comment 8 insights toc
more_vert
insights Stats

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

2) 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

3) Download Python binary package

wget https://www.python.org/ftp/python/3.9.1/Python-3.9.1.tgz

4) Unzip the package

tar -xzf Python-3.9.1.tgz

5) Execute configure script

cd Python-3.9.1

./configure --enable-optimizations

6) Build Python 3.9

make -j 2

7) Install Python 3.9

sudo make install

Verify the installation

Run the following command to install Python 3.9:

$ python3.9
Python 3.9.1 (default, Jan 8 2022, 14:44:10)
[GCC 6.3.0 20170516] on linux
Type "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'

2) 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

More from Kontext
comment Comments
G Glenn Glazer #1735 access_time 2 years ago more_vert

Ah, then this has nothing to do with WSL, then. It's "how to install a python version higher than that bundled with the distro". This would happen in regular Debian as well.

format_quote

person Raymond access_time 2 years ago

Hi, it is because the package is not available directly at the time when this article was published.

Raymond Raymond #1734 access_time 2 years ago more_vert

Hi, it is because the package is not available directly at the time when this article was published.

format_quote

person Glenn access_time 2 years ago

I don't understand why you would build python from source.

On WSL Debian bullseye:

glenn@RainbowDream:~$ sudo apt-get install python3
Reading package lists... Done
Building dependency tree... Done
The following additional packages will be installed:
  ca-certificates libexpat1 libmpdec3 libpython3-stdlib libpython3.9-minimal libpython3.9-stdlib libsqlite3-0
  media-types openssl python3-minimal python3.9 python3.9-minimal
Suggested packages:
  python3-doc python3-tk python3-venv python3.9-venv python3.9-doc binutils binfmt-support
The following NEW packages will be installed:
  ca-certificates libexpat1 libmpdec3 libpython3-stdlib libpython3.9-minimal libpython3.9-stdlib libsqlite3-0
  media-types openssl python3 python3-minimal python3.9 python3.9-minimal
0 upgraded, 13 newly installed, 0 to remove and 7 not upgraded.
Need to get 7,027 kB of archives.
After this operation, 23.8 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

followed by the download and install and to prove the point:

glenn@RainbowDream:~$ python3
Python 3.9.2 (default, Feb 28 2021, 17:03:44)
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.

G Glenn Glazer #1733 access_time 2 years ago more_vert

I don't understand why you would build python from source.

On WSL Debian bullseye:

glenn@RainbowDream:~$ sudo apt-get install python3
Reading package lists... Done
Building dependency tree... Done
The following additional packages will be installed:
  ca-certificates libexpat1 libmpdec3 libpython3-stdlib libpython3.9-minimal libpython3.9-stdlib libsqlite3-0
  media-types openssl python3-minimal python3.9 python3.9-minimal
Suggested packages:
  python3-doc python3-tk python3-venv python3.9-venv python3.9-doc binutils binfmt-support
The following NEW packages will be installed:
  ca-certificates libexpat1 libmpdec3 libpython3-stdlib libpython3.9-minimal libpython3.9-stdlib libsqlite3-0
  media-types openssl python3 python3-minimal python3.9 python3.9-minimal
0 upgraded, 13 newly installed, 0 to remove and 7 not upgraded.
Need to get 7,027 kB of archives.
After this operation, 23.8 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

followed by the download and install and to prove the point:

glenn@RainbowDream:~$ python3
Python 3.9.2 (default, Feb 28 2021, 17:03:44)
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.

Raymond Raymond #1721 access_time 2 years ago more_vert

I'm glad that you find it helpful :)

format_quote

person Alexander access_time 2 years ago

Thank you! Super useful

A Alexander Shipilov #1719 access_time 2 years ago more_vert

Thank you! Super useful

Raymond Raymond #1695 access_time 2 years ago more_vert

You are welcome! If you have other related questions, feel free to post it here.

format_quote

person Cathy access_time 2 years ago

Thanks so much for getting back to me! I cant find the pip3 executable, but I have been able to install modules with:

python -m pip install [module_name]


C Cathy Savino #1694 access_time 2 years ago more_vert

Thanks so much for getting back to me! I cant find the pip3 executable, but I have been able to install modules with:

python -m pip install [module_name]


format_quote

person Raymond access_time 2 years ago

Hi Cathy,

From Python 3.4, pip is included as part of Python installation binary.

Can you try the following command?

pip3

OR

python -m pip

If you find the pip is not installed by default, try using the following command to install it:

python -m ensurepip --default-pip

Reference:

Installing Python Modules — Python 3.10.6 documentation

Raymond Raymond #1692 access_time 2 years ago more_vert

Hi Cathy,

From Python 3.4, pip is included as part of Python installation binary.

Can you try the following command?

pip3

OR

python -m pip

If you find the pip is not installed by default, try using the following command to install it:

python -m ensurepip --default-pip

Reference:

Installing Python Modules — Python 3.10.6 documentation

format_quote

person Cathy access_time 2 years ago

Where is pip? It does not seem to be installed

C Cathy Savino #1690 access_time 2 years ago more_vert

Where is pip? It does not seem to be installed

Please log in or register to comment.

account_circle Log in person_add Register

Log in with external accounts