2

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.

2 Answers 2

2

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*
2
  • 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.
    – cas
    Oct 3, 2015 at 10:09
  • 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.
    – cas
    Oct 3, 2015 at 10:10
0

found a (similar )reddit thread here, wherein, they have discussed the same concern

You must log in to answer this question.

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