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.

Greenonline
  • 2,969
  • 5
  • 27
  • 38
John Foggitt
  • 91
  • 1
  • 1
  • 3

2 Answers2

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.

Dmitry Grigoryev
  • 28,277
  • 6
  • 54
  • 147
-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)

Alexey Vesnin
  • 926
  • 10
  • 17