Setting python3 to version 3.7 on WSL
19,708
Here's the steps to change your python3
command to point to your python3.7
version (assuming you already have 3.7 installed). Please adjust paths as needed for your environment
# 1 - Identify your location of `python3` using the `which` command
which python3
# returns something like
/usr/local/bin/python3
# 2 - Identify your location of `python3.7` using the `which` command
which python3.7
# returns something like
/usr/local/bin/python3.7
# 3 - Get directory listing of python3 folder (from 1 above)
# using grep to filter results containing 'python'
ll /usr/local/bin | grep -i python
# returns something like below - notice the arrow after python3
# the arrow indicates a symbolic link
lrwxrwxrwx 1 root root 18 Jul 4 2018 python3 -> /usr/bin/python3.6*
-rwxr-xr-x 2 root root 14777608 Nov 3 00:36 python3.7*
-rwxr-xr-x 2 root root 14777608 Nov 3 00:36 python3.7m*
-rwxr-xr-x 1 root root 3097 Nov 3 00:37 python3.7m-config*
-rwxr-xr-x 1 root root 4522328 Feb 22 17:24 python3x*
# 4 - Test creating a symbolic link using sudo to get root privileges
# enter password if/when prompted
sudo ln -s /usr/local/bin/python3.7 /usr/local/bin/test37
# 4 - verify test
test37 --version
# Desired output
Python 3.7.1
# 5 - remove test and python3
sudo rm /usr/local/bin/test37
sudo rm /usr/local/bin/python3
# 6 - creating python3 symbolic link using sudo to get root privileges
# enter password if/when prompted
sudo ln -s /usr/local/bin/python3.7 /usr/local/bin/python3
# 7 - verify
python3 --version
# Desired output
Python 3.7.1
Of course the pythonic thing to do is to use virtual environments.
Related videos on Youtube
Author by
wbadry
Updated on September 18, 2022Comments
-
wbadry almost 2 years
Can I change the default Python 3.6.5 on WSL Ubuntu 18.04 to 3.7? So when I check
python3 --version
I get3.7.x
so I can use that version with pip3 as well. Thanks-
DaveStSomeWhere over 5 yearsDoes
python3.7 --version
provide the desired output and are you just trying to avoid typing the extra .7? Have you considered virtual environments? -
wbadry over 5 yearsWhat I try to do is installing more packages for 3.7, not 3.6 version coming with ubuntu 18.04. PIP3 is associated with 3.6.5 and don't know how to install packages on 3.7
-
DaveStSomeWhere over 5 yearsYes, multiple steps to verify. 1 - verify python3.7 is installed by checking
python3.7 --version
. 2 - do you have root privileges, can you entersudo
commands. 3. Find your python3 symbolic link usingwhich python3
(should point to python3.6). 4 - remove python3 symbolic link. 5. Add new symbolic link to python3.7. Please verify 1 and 2. -
wbadry over 5 yearsWould you kindly post the Linux commands for this?
-
DaveStSomeWhere over 5 yearsI'll put them in an answer to format
-
-
asa over 3 yearsThis solves the problem but creates a new one. Now, I can't get Ubuntu upgraded, it always throws the message: ModuleNotFoundError: No module named 'apt_pkg'
-
Tes3awy over 2 years@asa Did you manage to solve the
apt_pkg
Exception?