9

If I double click on a .py file it opens "IDLE" (is there another way to open "IDLE"?), but the default python version is 2 when I select "run". I want to PERMANENTLY change the default version to 3 so that I don't have to switch versions every time I switch on my Raspberry Pi.

I have searched for this without success. Most answers predate the inclusion of Python 3 and explain how to install 3 but NOT how to switch the default, hence this question.

2
  • Did you try uninstalling python 2?
    – Bex
    Feb 19, 2016 at 7:19
  • 7
    @Bex, I would not uninstall py2 unless you're certain that it is not needed elsewhere. There are still many scripts out there that run on 2.7.
    – Ghanima
    Feb 19, 2016 at 7:41

2 Answers 2

5

IDLE is usually installed along with python, so you should have idle3 somewhere. Here's what you should do:

  1. Try to run idle3, idle3.3, idle3.4 etc. in the terminal to make sure you have it. Let's assume you have idle3

  2. Change the file association of .py files, so they are opened with idle3 when double-clicked. This depends on your file manager, usually righ-click -> "Open With..." does the trick.

Again, playing with symlinks is not a good idea, because scripts starting with #!/usr/bin/python expect to be executed with python2.

-2

a proper way to do it is to use Debain's update-alternatives

UPD: people are too lazy to jyst Read The Fine Manual :

update-alternatives --remove-all python
update-alternatives --install /usr/bin/python python /usr/python2/bin/python2 10
update-alternatives --install /usr/bin/python python /usr/python3/bin/python3 20

That's the way it should be. After that to switch the things up :

update-alternatives --set python "/usr/python2/bin/python2"

to select the one you need. It won't break PEP-394, because python2 and python3 binaries will be where they must be in multi-versioned install : in the installations' prefixes(usr/python2 and /usr/python3 respectively)

9
  • 3
    There is no link group for Python in update-alternatives.
    – n.st
    Feb 19, 2016 at 16:25
  • 1
    Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. Feb 19, 2016 at 18:34
  • 1
    update-alternatives are just a nice way to track symlinks in your system, so in the end your solution will hit the same problem as @Milliways': you'll replace /usr/bin/python, which is a violation of PEP-394. Feb 19, 2016 at 19:19
  • 1
    @n.st So you need to create it =) That's the idea : no package mess-up, standard switching mode Feb 19, 2016 at 19:24
  • 1
    PEP-394 specifically says that /usr/bin/python should point to python2, because many legacy scripts starting with #!/usr/bin/python only run correctly with python2. Feb 19, 2016 at 19:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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