How can I switch between Python 2.7 and 3.4 that are installed on Debian 8 (Jessie)?

13,678

Why not use #! /usr/bin/python2.7 when you want to use python 2.7 and #! /usr/bin/python3.4 when you want to use python 3.4?

Alternatively if you want your python programs to automatically use the latest python 2.x or python 3.x, use #!/usr/bin/python2 or #!/usr/bin/python3 - they are symlinks pointing to the latest versions, 2.7 and 3.4 respectively at the moment.

BTW, I have the following python interpreters installed on my debian sid system at the moment. They all work as expected.

lrwxrwxrwx 1 root root       9 Mar 17  2015 /usr/bin/python -> python2.7*
lrwxrwxrwx 1 root root       9 Mar 17  2015 /usr/bin/python2 -> python2.7*
-rwxr-xr-x 1 root root 2652824 May  9  2013 /usr/bin/python2.6*
-rwxr-xr-x 1 root root 3500648 Sep 14 11:04 /usr/bin/python2.7*
lrwxrwxrwx 1 root root       9 Jun 28 09:42 /usr/bin/python3 -> python3.4*
-rwxr-xr-x 1 root root 2965608 Nov 28  2010 /usr/bin/python3.1*
lrwxrwxrwx 1 root root      11 May  9  2013 /usr/bin/python3.2 -> python3.2mu*
-rwxr-xr-x 1 root root 2890040 May  9  2013 /usr/bin/python3.2mu*
-rwxr-xr-x 2 root root 4148216 Sep 24 11:22 /usr/bin/python3.4*
-rwxr-xr-x 2 root root 4148216 Sep 24 11:22 /usr/bin/python3.4m*
lrwxrwxrwx 1 root root      10 Jun 28 09:42 /usr/bin/python3m -> python3.4m*
Share:
13,678

Related videos on Youtube

Alessio
Author by

Alessio

Please note: If I post a comment on a question or an answer, I have no objection at all if anyone "steals" ideas from the comment and uses them to write a good answer. In fact, sometimes I leave comments deliberately for people to do that because I don't have the time or the inclination to develop them into a complete answer. I don't even mind if you take an idea from my comment and type up an answer based on it faster than I can. Ideas can not be stolen, they're not property to begin with. This is pretty much rough-consensus on how comments should be treated on SE sites anyway. IF YOU DO NOT ALREADY KNOW ME IN REAL LIFE, DO NOT EMAIL ME OR CONTACT ME ABOUT SE ANYWHERE BUT ON SE. I WILL NOT RESPOND, AND WILL ADD YOU TO MY BLOCK LIST.

Updated on September 18, 2022

Comments

  • Alessio
    Alessio over 1 year

    I'm using Debian 8.2 (Jessie), and have both Python 2.7 and 3.4 installed. Python 2.7 is the default and that's what is used when I run a Python script or interactively in the Terminal.

    How can I switch between the two Python versions? I would like to start working in Python 3.4, and still be able to revert to 2.7.

  • Alessio
    Alessio over 8 years
    yep, it's that simple. and that method is fine. note, though, that running python rather than python2 is potentially unreliable - eventually that symlink will probably point to python 3.x rather than 2.x. best to explicity use the python2 or python3 symlinks.
  • Alessio
    Alessio over 8 years
    BTW, you don't need to specify the full path to either python, python2 or python3 etc on the command line as they're all in the $PATH (/usr/bin). You only need to specify the full path on the #! line in a script file.