1

How do you remove Python2 and Python3 that comes with macOS? I have Python3 installed using Anaconda and would like to get rid of the original Python2 and Python3.

0

Simply put you cannot. You would damage the system and violate Apple's Gatekeeper security which protects system files. Gatekeeper would then restore those files if it did not already break the OS due to internal use of Python code and cause you to fail to boot.

MacOS is not designed to be a configurable OS. Frameworks that come with the OS are used by the OS, aside from those that reside in your Applications folder itself. Apple MUST have a version of all initially supplied frameworks present as the OS itself needs a backstop should your Anaconda install be removed. Any internal python code will be hard-wired (as in direct unmodifiable access) to those frameworks and will not use any others. Same with Java and such.

Your comment to the other answer however is your real question. You want to compile using non internal Python and I believe the way to do that is to change the PATH variable of Python to point to Anaconda's one.

export PATH="/Users/username/anaconda3/bin:$PATH" into .bash_profile or .zshrc will do it.

The #include headers are not where your Python location should be selected btw. It should either be in your IDE settings or directly in the variables you provide to the compiler on make.

1

You can't -- at least, not without breaking things. (Which I won't advise you on how to do.)

In macOS Mojave (10.14) and earlier, Python 2.7 is a core component of the operating system, and cannot be removed. Some parts of the operating system may depend on its presence; removing it is likely to cause incorrect behavior. Python 3, however, is not part of the operating system -- if it is present on your computer, it's because you installed it, or a piece of software which included it. How you remove it will depend on how it was installed.

In macOS Catalina (10.15), Python 2.7 remains a core component of the operating system, and Python 3 can be installed as part of the Xcode toolchain. (macOS Catalina is expected to be released in September 2019.)

  • I've been trying to write a Python extension with C++, and when I #include <Python/Python.h> it would use the headers in /Library/Developer/CommandLinetools/... even when I explicity force the compiler to include the specific folder with Python headers from anaconda. Do you know if there is a way to deal with this? – Brian Ko Jul 11 at 20:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.