10

I have both python3.6 and python3.5 on ubuntu (zesty beta 2). I know that python calls python2.7. The problem is, when I call python3, it automatically starts python3.5 instead of python3.6.

Is there a better way to fix this than an alias?

4
  • 1
    What is wrong with aliases ?
    – Ravexina
    Commented Apr 5, 2017 at 15:54
  • @Ravexina Don't they slow down shells? Commented Apr 5, 2017 at 15:56
  • I'm not sure they do: Do aliases slow down a shell's start?
    – Ravexina
    Commented Apr 5, 2017 at 16:06
  • 1
    Changing the system-provided version of Python risks breaking your system. Many essential system services (like apt) are tested against the system-provided version of Python. Best way to experiment with different versions of Python is in a VM.
    – user535733
    Commented Apr 5, 2017 at 16:07

3 Answers 3

10

Changing the default python3 version might break many things on your system, and I'd advise against making python3 point to python3.6. Better to simply call python3.6 explicitly in those programs where it matters, and leave the python3 symlink as is.

4

As an alternative to aliases you can use update-alternatives:

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

This command will create a link in: /usr/bin/python3 to /usr/bin/python3.6.

I'm not sure if it's a good idea, maybe an update makes it broken.

An other options is creating a link to desired version of python in ~/bin then adding this path to the $PATH environment variable:

export PATH=/home/$USER/bin:$PATH

Or within your .profile:

PATH=/home/$USER/bin:$PATH
1
  • 1
    This will break things that are expecting python3 to be python3.5 (as at 17.04). For example, launching a terminal will not work and the update indicator will fail. Actually breaks apt pretty badly. Commented Jul 15, 2017 at 23:02
0

Regarding your actual question (whether it's a good idea or not, I leave aside), you can check your /usr/bin/python3 version (in my case it was 3.4 ), and replace it with the new version:

$ python3 -V
  Python 3.4.9

$ ls -lh /usr/bin/python3
  lrwxrwxrwx. 1 root root  9 Dec  5 16:35 /usr/bin/python3 -> python3.4

$ sudo mv /usr/bin/python3 /usr/bin/_python3
$ sudo cp /usr/bin/python3.6 /usr/bin/python3

$ python3 -V
  Python 3.6.6
3
  • 1
    It's not a good idea. Don't do this, it will break things like Gnome Terminal and APT.
    – wjandrea
    Commented Sep 5, 2020 at 23:36
  • 1
    @wjandrea, that's why I explicitly said to put aside "whether it's a good idea or not". I simply answered the OP question: How to change python3 from python3.5 to python3.6 ?
    – Noam Manos
    Commented Sep 7, 2020 at 12:12
  • Just because you can doesn't mean you should.
    – wjandrea
    Commented Sep 7, 2020 at 12:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .