Link python3 to python3 7

I would like to expand on a previous answer as the two approaches given are not equivalent, and one of them can even break the system. The issue is there are two different things one could be trying to do by "changing the default python version".

Quick summary

Add

alias python3=python3.7

to .bashrc.

Do not use update-alternatives to change your default python version, as this will break system applications.

Further details

Bash alias

The first, is that for an interactive shell, one simply wishes to easily open the desired python by writing

$ python

or

$ python3

This is accomplished by adding the line

alias python3=python3.7

to .bashrc. If one is using another shell, add this to the appropriate config file. This also has the advantage that if it causes problems for any reason, one can simply remove the offending line in .bashrc and restart the terminal.

update-alternatives

The second thing one could mean by "changing the default python version", is to change the default python version for all programs, including those not launched from an interactive shell. This is the result of running

$ sudo update-alternatives --config python3

However, if you run this in a clean install of Debian/Ubuntu, you will notice that the command returns

update-alternatives: error: no alternatives for python3

even if you have multiple versions of python 3 installed via apt. There is a very good reason for this.

The problem with the this is that many system applications use python, and depending on the exact distribution, many use python 3. Changing which version is called by the command python3 globally will force these applications to use this version. Although different version of python 3 are largely compatible, there are still features moved and removed between releases. If a system application uses these features, changing python3 to launch a newer version will break the application.

Testing

I created a fresh install of Ubuntu 18.04 in a VM. Adding the bash alias caused no immediate issues.

Using the update-alternatives method caused issues with apt. Specifically, I got

ModuleNotFoundError: No module named 'apt_pkg'

Fixing your system if you ran the update-alternatives method

If we ran update-alternatives and broke apt, we can still fix the system. During my testing, the terminal was still able to be opened. One can go back to the default python by running

$ sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.X 1000

where 3.X is your systems original python 3 version, and 1000 is just some high priority to make sure it is on top. Then, one can run

$ sudo update-alternatives --config python3

and make sure the original system python is selected. Reboot the system and it will be back to normal.

I have a Python 3.6.8 in /usr/local/bin/Python3 and a Python 3.7.6 in /usr/local/bin/Python3.7 on my Macbook [In addition, there is Mac default Python2, which I don't want to change it].

By check which python3 or python3 --version, I can see the current default version is Python 3.6.8. I'd like to set the default Python3 to Python 3.7.6. How can I do that?

asked May 15, 2020 at 3:42

You can use the "ln" command to create a symbolic link [symlink] to the existing file as:

ln -s -f /usr/local/bin/Python3.7 /usr/local/bin/python

In order to be sure you can close your terminal and then open it again to check the changes default version as before.

python3 --version

answered May 15, 2020 at 4:18

Anya SamadiAnya Samadi

5931 gold badge4 silver badges13 bronze badges

Not the answer you're looking for? Browse other questions tagged python python-3.x macos or ask your own question.

Is it possible to symlink Python 3 to Python 3?

And there are also applications that work with Python 3. Since Python 3 is not backwards compatible, by symlinking python to python3 you break a lot of dependencies, hence a lot of applications not working. Not the answer you're looking for?

Is there a way to run Python 3 from some system?

some system may still use Python 2 to run some functions and sometimes changing symlink may crush system. Better use command python3 or python3.8 to run Python 3 maybe you have other command python in current folder and it may run this command instead of /Users/overflow/Documents/tools/python .

Is it possible to change the symbolic link of Python 3?

It is not recommended to change the symbolic link because of other package dependencies, but they "have ongoing project goals to make Python 3 the default, preferred Python version in the distros".

How do I use Python3 instead of Python 2 7?

If you want to use python3 instead of python2.7 just when you manually run python applications, just add: to your ~/.bash_aliases file. [The file may be empty depending on whether you have added any aliases in the past.] The applications other than the ones you manually start will continue using python2.7 or python3 as before.

How does Python connect to python3 7?

Worked well for me..
sudo apt-install python3.7 Install the latest version of python you want..
cd /usr/bin Enter the root directory where python is installed..
sudo unlink python or sudo unlink python3 . ... .
sudo ln -sv /usr/bin/python3.7 python Link the new downloaded python version..

How do I connect python3 to python3 6?

Better to simply call python3. 6 explicitly in those programs where it matters, and leave the python3 symlink as is. This command will create a link in: /usr/bin/python3 to /usr/bin/python3. 6 .

How do I make Python 3.7 my default Ubuntu?

Switch Python Version on Ubuntu & Debian.
Create a symlink from /usr/bin/python2. ... .
Change the symlink link to /usr/bin/python3. ... .
Repeat step 2 to add more Python version to group, which is already installed on your system..
At this point, You have added two python binary versions to the group name “python”. ... .
That's it..

How do I make python3 default?

Steps to Set Python3 as Default On ubuntu?.
Check python version on terminal - python --version..
Get root user privileges. On terminal type - sudo su..
Write down the root user password..
Execute this command to switch to python 3.6. ... .
Check python version - python --version..
All Done!.

Chủ Đề