0

I want to unistall Python in my Mac. I tried to removed it from /Library/Frameworks/ using sudo rm -rf /Library/Frameworks/Python.framework and and from Applications too. But yet i have Python 2.7.10 when i use Python -V

How i can delete and unistall Python from my mac please?

Thanks.

parik
  • 2,313
  • 12
  • 39
  • 67
  • 5
    Python is part of MacOS, I don't believe you can *remove* it without messing up the OS... You don't specify *why* you want to do it, but an educated guess is that [this](https://virtualenv.readthedocs.org/en/latest/) may help. – Nir Alfasi Feb 17 '16 at 20:51
  • I installed python3.5.1 but when i use Python -V i have already 2.7.10 – parik Feb 17 '16 at 20:54
  • What about `python3 -V`? Or using a `virtualenv`? – jonrsharpe Feb 17 '16 at 21:04
  • in /Library/Frameworks/Python.framework/Versions i have just 3.5 but Pythob -V give me 2.7.10, i'm really confused – parik Feb 17 '16 at 21:06
  • python3 -V give me 3.5 but virtualenv use System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py" – parik Feb 17 '16 at 21:08
  • 1
    What about `python3 -m virtualenv venv`? – OneCricketeer Feb 17 '16 at 21:11
  • Also, `/usr/bin/python` is most likely the executable you are running. Not sure what deleting that Framework folder does because it doesn't exist on my Mac – OneCricketeer Feb 17 '16 at 21:14
  • python3 -m virtualenv venv /Library/Frameworks/Python.framework/Versions/3.5/bin/python3: No module named virtualenv – parik Feb 17 '16 at 21:19

1 Answers1

3

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

  1. The files have to be somewhere on your machine
  2. Your PATH has to point to this new python
  3. (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!

Community
  • 1
  • 1
AnilRedshift
  • 7,937
  • 7
  • 35
  • 59