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?

tripleee
  • 175,061
  • 34
  • 275
  • 318
frazman
  • 32,081
  • 75
  • 184
  • 269

2 Answers2

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
AcaNg
  • 704
  • 1
  • 9
  • 26
  • 1
    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. – tripleee Aug 06 '19 at 04:06
  • @tripleee 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`). – AcaNg Aug 06 '19 at 04:49
  • Oh, I'm pretty sure this is a duplicate anyway. – tripleee Aug 06 '19 at 04:55
0

you can use softlink

ln -s /usr/bin/python /usr/local/bin/python3.7
DennisLi
  • 3,915
  • 6
  • 30
  • 66