Page 1 of 1

How to set python 3.5 as a default language in raspberry pi 3?

Posted: Mon Jul 15, 2019 12:38 pm
by arpitbt
I tried to set python 3.5 using command

cd Desktop
alias python="/usr/bin/python3.5"

but whenever system reboot or restart it again set python2.7 as its default language.I want to set python3.5 as permanently default language.

Re: How to set python 3.5 as a default language in raspberry pi 3?

Posted: Mon Jul 15, 2019 1:11 pm
by klricks
arpitbt wrote:
Mon Jul 15, 2019 12:38 pm
I tried to set python 3.5 using command

cd Desktop
alias python="/usr/bin/python3.5"

but whenever system reboot or restart it again set python2.7 as its default language.I want to set python3.5 as permanently default language.
There is no default.
python = python2 forever
Use python3

Re: How to set python 3.5 as a default language in raspberry pi 3?

Posted: Mon Jul 15, 2019 1:50 pm
by B.Goode
arpitbt wrote:
Mon Jul 15, 2019 12:38 pm
I tried to set python 3.5 using command

cd Desktop
alias python="/usr/bin/python3.5"

but whenever system reboot or restart it again set python2.7 as its default language.I want to set python3.5 as permanently default language.


Your system is working as designed.


A shell alias is only active for the life of that shell.

If you want that alias implemented for every login you need to invoke it every time. I think .bashrc might be the appropriate place.

But:
1. Beware of causing yourself confusion and frustration by implementing a non-standard solution;
2. Hasn't python3.5 been superseded by a later version in the current release of Raspbian?


(The cd Desktop is redundant.)

Re: How to set python 3.5 as a default language in raspberry pi 3?

Posted: Mon Jul 15, 2019 3:02 pm
by DougieLawson
If you positively understand that changing /usr/bin/python to run python3 may break your system, you can fiddle with the symbolic links in /usr/bin.

Code: Select all

pi@viking /tmp $ cd /usr/bin
pi@viking /usr/bin $ ls -la python*
lrwxrwxrwx 1 root root       9 Jan 24  2017 python -> python2.7
lrwxrwxrwx 1 root root       9 Jan 24  2017 python2 -> python2.7
-rwxr-xr-x 1 root root 3166320 Sep 26  2018 python2.7
lrwxrwxrwx 1 root root      36 Sep 26  2018 python2.7-config -> arm-linux-gnueabihf-python2.7-config
-rwxr-xr-x 1 root root 7145800 Sep 26  2018 python2.7-dbg
lrwxrwxrwx 1 root root      40 Sep 26  2018 python2.7-dbg-config -> arm-linux-gnueabihf-python2.7-dbg-config
lrwxrwxrwx 1 root root      16 Jan 24  2017 python2-config -> python2.7-config
lrwxrwxrwx 1 root root      13 Jan 24  2017 python2-dbg -> python2.7-dbg
lrwxrwxrwx 1 root root      20 Jan 24  2017 python2-dbg-config -> python2.7-dbg-config
-rwxr-xr-x 1 root root     154 Sep 21  2016 python2-pbr
-rwxr-xr-x 1 root root     285 Aug 22  2016 python2-qr
lrwxrwxrwx 1 root root       9 Jan 20  2017 python3 -> python3.5
-rwxr-xr-x 2 root root 3976256 Sep 27  2018 python3.5
lrwxrwxrwx 1 root root      36 Sep 27  2018 python3.5-config -> arm-linux-gnueabihf-python3.5-config
-rwxr-xr-x 2 root root 3976256 Sep 27  2018 python3.5m
lrwxrwxrwx 1 root root      37 Sep 27  2018 python3.5m-config -> arm-linux-gnueabihf-python3.5m-config
lrwxrwxrwx 1 root root      16 Jan 20  2017 python3-config -> python3.5-config
lrwxrwxrwx 1 root root      10 Jan 20  2017 python3m -> python3.5m
lrwxrwxrwx 1 root root      17 Jan 20  2017 python3m-config -> python3.5m-config
lrwxrwxrwx 1 root root      16 Jan 24  2017 python-config -> python2.7-config
lrwxrwxrwx 1 root root      13 Jan 24  2017 python-dbg -> python2.7-dbg
lrwxrwxrwx 1 root root      20 Jan 24  2017 python-dbg-config -> python2.7-dbg-config
lrwxrwxrwx 1 root root      58 Mar 13  2017 pythontex -> ../share/texlive/texmf-dist/scripts/pythontex/pythontex.py
-rwxr-xr-x 1 root root     306 Mar 13  2017 pythontex3

python links to python2.7
so
sudo rm /usr/bin/python
sudo ln -s /usr/bin/python3 /usr/bin/python

will make python run python3.

When things break put the overly complex mess above (in that code block) back in place.

Re: How to set python 3.5 as a default language in raspberry pi 3?

Posted: Mon Jul 15, 2019 3:31 pm
by jahboater
I add a line to ~/.bashrc

alias python=python3

That means any system software that depends on python being python2 will still work.

Re: How to set python 3.5 as a default language in raspberry pi 3?

Posted: Mon Jul 15, 2019 5:39 pm
by Andyroo
jahboater wrote:
Mon Jul 15, 2019 3:31 pm
I add a line to ~/.bashrc

alias python=python3

That means any system software that depends on python being python2 will still work.
Assuming:

1) You do not call it from your shell
2) Its set to use Python 2.x and not just Python surely :?: ? :?:

Re: How to set python 3.5 as a default language in raspberry pi 3?

Posted: Tue Jul 16, 2019 5:08 am
by arpitbt
My program based on python3 so if i boot directly from my program will it work fine? Because when program switch from one version to other it gives me an error at run time.

Re: How to set python 3.5 as a default language in raspberry pi 3?

Posted: Tue Jul 16, 2019 6:22 am
by B.Goode
My program based on python3 so if i boot directly from my program will it work fine?


If your program runs correctly it will not make any difference how your system was rebooted.

Re: How to set python 3.5 as a default language in raspberry pi 3?

Posted: Wed Jul 17, 2019 9:14 am
by blimpyway
You do not change OS's default python version because you do not know if or which other scripts do not require that specific version.
Instead you should tell the OS what python interpreter you want to run your script:

e.g. create the following file named runp3.py

Code: Select all

#!/usr/bin/python3

import sys
print(sys.version)
then in command shell:

Code: Select all

 
 $ chmod +x runp3.py
 $ ./runp3 
 
Which outputs on my pi:

Code: Select all

3.5.3 (default, Sep 27 2018, 17:25:39) 
[GCC 6.3.0 20170516]