4

I want to make python 3 as default in raspberry pi 3b and install scikit-learn and scikit-plot for the python 3 version. What are exact steps to be followed. Appreciate your input. Thank you

Dattaprasad
  • 43
  • 1
  • 1
  • 4
  • What do you mean by make python3 as default? –  Jul 10 '17 at 05:16
  • @yamboy1, yes. Can it be done by adding 'alias python=python3' in the ~/.bashrc file and then typing alias python=python3. But then how to revert to python2. – Dattaprasad Jul 10 '17 at 05:17
  • @yamboy1, sorry for not mentioning it clearly. Making python 3 default means whenvever I open a py file, it should open in python 3 IDLE. And when I install any new package it should be for the python version 3. In my case, currently basic packages such as scipy and numpy are installed for python 2, but when I run a code in python 3 IDLE, I get error....Import Error: No module named 'scipy' – Dattaprasad Jul 10 '17 at 05:20
  • 1
    https://askubuntu.com/questions/320996/how-to-make-python-program-command-execute-python-3 covers the details you need to beaware of as for python2 after aliasing python3 create aa second alias for python2 – Steve Robillard Jul 10 '17 at 06:36
  • What operating system do you use? – Bex Aug 18 '17 at 08:43
  • For the raspberry pi 3b, the default OS raspbian is used. – Dattaprasad Aug 20 '17 at 06:50

1 Answers1

3

If you run linux command ls -l python* within the directory, you will see that python is just a symlink to python2.7, if you know linux commands well enough, you can easily make a change to link python -> python3.

One more thing you need to aware is that in order to install packages for python3, you need to run pip3. This is probably the reason that you run into the case where "No module name 'script'" error. Again, run ls -l pip* to find out more.

You can also run pip3 list to check what packages are installed for python3.

hcheung
  • 845
  • 7
  • 14
  • 3
    For many reasons, it is not a good idea to point /usr/bin/python to python3. See for example https://stackoverflow.com/questions/43062608/how-to-update-alternatives-to-python-3-without-breaking-apt – Bex Aug 18 '17 at 08:52
  • @Bex, I won't recommend messing with the default installation either (which is the link that you referred to is doing). However, to put a symbolic link so that typing python to launch python3 instead of the default python2 is a different story, and do no harm for the fundamental system installation. – hcheung Aug 18 '17 at 09:35
  • 2
    Instead of changing the default system-wide you could change it just for your pi-user. Do this: sudo apt install python3; mkdir ~/bin; ln -s /usr/bin/python3 ~/bin/python. Log your user out and log back in. Do this: which python, This should return /home/pi/bin/python. Now everthing under this user will use the symlink which points to python3. Delete ~/bin/python, log out and back in to revert this change. – MadMike Aug 18 '17 at 11:25