Do not remove the system python. Consider it part of the operating system, and note that OS upgrades may restore that folder.
Instead, what it sounds like is that you want to have multiple python versions installed at the same time. There are several ways of doing this. The short version is that
- The files have to be somewhere on your machine
- Your
PATH
has to point to this new python
- (optional) in the case of running python3, you may wish for
python
to execute python3.
Let's solve these problems one at a time.
Installing python
It appears that you already have a version of python 3.5 installed, but you can also install it with brew
or pyenv
To use brew
, see these instructions: http://docs.python-guide.org/en/latest/starting/install/osx/
pyenv
is a brew package, so to use it, you would first install brew and then install a version of python. See: https://github.com/yyuu/pyenv#homebrew-on-mac-os-x
Fixing the path
$PATH
is an environment variable that is a list of directories. To see your current path, type in echo $PATH
into a terminal. Each directory is delimited by a semicolon(:
). When you type python
in the terminal, the computer goes through each directory, in order, until it finds a file named python. So, this is why trying to execute python
gives you the system python instead of the one you downloaded.
There are a couple ways of fixing this. Instead of running python
, you could give an explicit path to wherever your new python binary is (for example /usr/local/bin/python3
would launch the binary of python installed by brew
.
Typing a path manually every time is hard, and not all applications do this, so one option would be to add your new directory to $PATH. See: How to add /usr/local/bin in $PATH on Mac . This is a great option if you want to add a new python3
(since it doesn't exist in the original OS), but doesn't help if you want to override the existing python
The other (better) option is to use virtual environments to temporarily change your PATH so that you can run the version of python that you want, without breaking other applications. This option also would let you run python
and have it launch either python2 or python3 respectively. There are a few ways to get virtualenv
working. You can read more here: https://virtualenvwrapper.readthedocs.org/en/latest/install.html
If you have brew
installed, I would brew install python python-virtualenvwrapper
Hope this helps!