arpitbt
Posts: 12
Joined: Wed Jul 10, 2019 8:57 am

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

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.

klricks
Posts: 6626
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

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

Mon Jul 15, 2019 1:11 pm

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
Unless specified otherwise my response is based on the latest and fully updated Raspbian Buster w/ Desktop OS.

User avatar
B.Goode
Posts: 8987
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

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

Mon Jul 15, 2019 1:50 pm

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.)

User avatar
DougieLawson
Posts: 36578
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

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

Mon Jul 15, 2019 3:02 pm

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.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

jahboater
Posts: 4846
Joined: Wed Feb 04, 2015 6:38 pm

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

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.

Andyroo

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

Mon Jul 15, 2019 5:39 pm

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 :?: ? :?:

arpitbt
Posts: 12
Joined: Wed Jul 10, 2019 8:57 am

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

Tue Jul 16, 2019 5:08 am

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.

User avatar
B.Goode
Posts: 8987
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

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

Tue Jul 16, 2019 6:22 am

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.

blimpyway
Posts: 192
Joined: Mon Mar 19, 2018 1:18 pm

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

Wed Jul 17, 2019 9:14 am

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]

Return to “Python”