FreakShow!
Posts: 11
Joined: Thu Jul 05, 2012 3:01 pm

Remove Python2?

Fri Jul 12, 2019 9:33 pm

I'm getting back to learning Python and am chipping my way along. One issue I keep hitting is running Python v2.7.16 instead of Python v3.7.3. It's an easy mistake to make, but is there a way I can make Python 3 and Pip 3 the default when typing python/pip?

Andyroo
Posts: 3776
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: Remove Python2?

Fri Jul 12, 2019 9:44 pm

Not wise as lots of bits use Python 2 - in fact there have been posts here saying do not do it.

The safest way may be to make it local to you by putting a line into ~/.bashrc

Code: Select all

alias python='/usr/bin/pythonx.x.x
where x.x.x is the executable name you want to use

Once done, log in again to activate the alias.
Need Pi spray - these things are breeding in my house...

FreakShow!
Posts: 11
Joined: Thu Jul 05, 2012 3:01 pm

Re: Remove Python2?

Fri Jul 12, 2019 11:54 pm

Ah, I guess I should have realised that. I assume the alias is just for when I call it in terminal, but won't affect anything else calling python to do whatever it needs?

Andyroo
Posts: 3776
Joined: Sat Jun 16, 2018 12:49 am
Location: Lincs U.K.

Re: Remove Python2?

Sat Jul 13, 2019 12:55 am

Basically yes.

Thonny (the GUI editor) is set to Python 3 now.

You can also add a shebang as the first line, chmod the file to be executable and not use the python command as an option :lol:

Have a read of https://www.raspberrypi.org/forums/view ... 2&t=241830 for a bit more background.
Need Pi spray - these things are breeding in my house...

FreakShow!
Posts: 11
Joined: Thu Jul 05, 2012 3:01 pm

Re: Remove Python2?

Sat Jul 13, 2019 12:09 pm

Thanks for your help :)

Return to “Python”