Make "python" run python3 at the prompt [duplicate]
Asked Answered
L

2

0

I have two python installations..

python --> /Users/fraz/anaconda/bin/python (python2.7)

python3.7 --> /usr/local/bin/python3.7

Now.. I want reassign the commands. Such that python points to python3.7 --> /usr/local/bin/python3.7

and python2 points to python2.7 /Users/fraz/anaconda/bin/python

How do i do this reassignment?

Lightfingered answered 6/8, 2019 at 3:26 Comment(2)
What environment are you using? Linux? Windows?Chery
@Chery oops.. macLightfingered
F
1

follow this question, modify your ~/.bashrc, add a new line:

alias python=python3.7

save and exit then open terminal, type

source ~/.bashrc

in my machine, typing python2 will open python 2.x by default. but if needed, you can add a new alias

alias python2=python2.7
Furness answered 6/8, 2019 at 3:35 Comment(3)
This is specific to Bash, and to interactive sessions. A more portable solution which works for any shell is to add $HOME/bin (or whatever you want to call it) to the very front of your PATH, and populate it with symlinks to your preferred version whenever you want to override the system-wide default. If you have third-party scripts you rely on, they will generally expect python to run Python 2, though; so perhaps a better and more robust solution is to just learn to type python3 when that's what you mean.Nonetheless
@Nonetheless would you mind posting a new answer so I can upvote it ? btw I agree with you, people should get used to typing python3 (or python2).Furness
Oh, I'm pretty sure this is a duplicate anyway.Nonetheless
L
0

you can use softlink

ln -s /usr/bin/python /usr/local/bin/python3.7
Letters answered 6/8, 2019 at 4:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.