5

I have installed python3.7 however I am not sure how to make it the default python.

See below:

~/Documents/robosuite$ python3.7
Python 3.7.1 (default, Oct 22 2018, 11:21:55) 
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 
KeyboardInterrupt
>>> 

~/Documents/robosuite$ python3
Python 3.6.7 (default, Oct 22 2018, 11:32:17) 
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

I want python3.7 to show up when I use the command python3

8

Simple solution is edit .bashrc and put this line:

alias python3=python3.7

Whenever you will write python3 it will replace it with python3.7.

Or you can use command update-alternatives which is preferred i.e:

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.7 2

So here python3.7 will have higher priority then python3.6. Then use:

sudo update-alternatives --config python
  • 2
    Trap for young players: I highly recommend using update-alternatives over the alias-approach, as aliases do not take effect in non-shell environments (also non-interactive shells ignore .bashrc). Take a python-file starting with the shebang #!/usr/bin/env python3 as an example: Run with ./myscript.py it would ignore your alias, while python3 myscript.py would run in python 3.7.1 in your case. Other common cases for ambiguities would be invoking commands via ssh, or from inside a shell-script. – Folfy Jan 24 at 15:55
  • 1
    Note that the alternatives variant above replaces /usr/bin/python instead of /usr/bin/python3, and will cause issues with Python programs which expect python to be Python 2 (which is the case on Debian and derivatives). See also PEP 394 and the Debian Python policy. – Stephen Kitt Feb 11 at 6:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.