I generally use Python 2.7 but recently installed Python 3.5 using Miniconda on Mac OS X. Different libraries have been installed for these two versions of python. Now, the entering either of the keywords ‘python’ or ‘python3’ in terminal invokes python 3.5, and ‘python2’ returns ‘-bash: python2: command not found’. How can I now invoke them specifically using aliases ‘python2’ and ‘python3’ respectively?
I am currently using OS X El Capitan.
Answer
IMHO, the best way to use two different Python versions on macOS is via homebrew
. After installing homebrew on macOS, run the commands below on your terminal.
brew install python@2
brew install python
Now you can run Python 2.7 by invoking python2
or Python 3 by invoking python3
. In addition to this, you can use virtualenv
or pyenv to manage different versions of python
environments.
I have never personally used miniconda
but from the documentation, it looks like it is similar to using pip
and virtualenv
in combination.
Attribution
Source : Link , Question Author : Viswanath , Answer Author : Jakub Kukul