Removing older versions of Python from iMac

I have 2 Python folders, 3.6 and 3.7 in my applications folder on my iMac. Is there a tutorial that exists anywhere to explain how to safely and reliably remove these versions of Python?

That will probably depend on how they got there in the first place.

Well, I donā€™t quite remember but I think I installed them both from the Python.org site. The real problem I have is that when I download a library using VSCode (itā€™s called pygame), the librrary gets placed in the 3.6 profile. Since Iā€™m running 3.7, when I try to run a program, Iā€™m getting a message: ā€˜Canā€™t find the pygame moduleā€™. Trying to sort this one out is way beyond my skill level so I thought the safest thing was to uninstall 3.6 and 3.7and install the new version- 3.12. Any thoughts. Thanks very much for the response.

See uninstall references in 5. Using Python on a Mac ā€” Python 3.12.0 documentation

In this case itā€™s straightforward, and Barry gave you the necessary reference. I mainly wanted to underscore that you should never try to remove a version of Python that came with your computer, even if it is quite old, because you can seriously damage your operating system this way. (Update the operating system instead, if possible.)

3.6 and 3.7 are both past EOL and not supported any more, so this is a fine time to upgrade, and the way you have in mind makes perfect sense.

However, it is not difficult to sort out the problem you describe, and itā€™s a fundamental skill that will serve you well in the long run, so I recommend looking into it anyway.

When you install a third-party library for Python, each installation (what you called a ā€œprofileā€) has its own set of libraries, yes. Most installations of Python will include their own corresponding copy of Pip (if Python came with your operating system, that installation might not include Pip, for security reasons). Each Pip is associated with the Python it came with, and will install libraries for that Python. The cleanest, simplest (using only bare-bones tools) way to make sure that you install for the right Python is:

  • Use a Terminal window.
  • Make sure you know how to run the Python you want. If you know its path on disk, you can specify the full path; or you can make sure that your system is configured so that e.g. python means the Python you want. (Old systems might be configured in a way that python means a Python 2.x installation that came with the operating system; in this case, it may be easier to make python3 do what you want.)
  • Run that Python, and have it execute the Pip module (there is a separate wrapper script that lets you use Pip as a standalone program, but almost all of Pip is stored as a Python library). Assuming python means the Python you want, this looks like python -m pip install pygame (or replace pygame with the PyPI name for the library you want - this is not necessarily the name you will use to import in your code).

Editors like VSCode try to make this a bit smoother for you, but you will still need to mess around in the editorā€™s settings and research a bit about how it works.


PyGame is a pretty popular library, so you should be able to get help with using it fairly easily here.

If you plan to use really big libraries for heavy number crunching, machine-learning type tasks etc., note that a lot of the time they will not be compatible with the latest Python version, depending on the exact circumstances. Many of them integrate a lot of code in other languages like C, and making this work for every platform is quite tricky (Python implements a virtual machine, so pure-Python projects are normally cross-platform automatically with little or no effort). Sometimes you will need to roll back to the previous minor version of Python - one of the many reasons why itā€™s good to learn how to manage multiple installations.

1 Like

FYI I think this only applies to linux and the *BSD OSā€™s.

You cannot remove the Apple version of python from the OS.
Its on a read-only part of the system that the macOS makes very hard to change.

Pythonā€™s that are in /Applications are the ones from python.org and can be removed without macOS operations being affected in any way.

1 Like

Good to know. I havenā€™t regularly used a Mac since the early 2000s, so Iā€™ve been stating the advice in a general form based on what information I had.

Thanks for your help. I didnā€™t understand most of what you said. Like I said, just beyond my skill level. So I installed python3.12 from the website. Now I have 3 folders in the applications folder- Python 3.6, Python 3.7 and Python 3.12. All Iā€™m trying to do at this point to get my feet wet is to simply run a program in the VSCode editor. The program is named ā€˜spaceinvaders.pyā€™. So hereā€™s the Terminalā€™s response: /Library/Frameworks/Python.framework/Versions/3.12/Resources/Python.app/Contents/MacOS/Python: canā€™t open file ā€˜/Users/Jim/*CODING/Python Projects/Jims Projects/spaceinvaders.pyā€™: [Errno 2] No such file or directory
Can anyone tell me how to fix this? Iā€™m also getting the feeling that running Python on a Mac is troublesome, to say the least. Does anyone on this forum use a Mac or should I switch over to my PC and use Windows? Thanks, JIm

Thanks Barry. I read the whole article and there was no mention of uninstalling. By the way, are you a professional programmer? Iā€™m looking for someone I could hire to help me get set up with Python on a Mac. Iā€™m clearly not doing this right. Any suggestions on where I could find someone to work virtually. Thanksā€¦

Let me quote it for you, because itā€™s not very well organized:

What you get after installing is a number of things:

  • A Python 3.12 folder in your Applications folder. In here you find IDLE, the development environment that is a standard part of official Python distributions; and PythonLauncher, which handles double-clicking Python scripts from the Finder.
  • A framework /Library/Frameworks/Python.framework, which includes the Python executable and libraries. The installer adds this location to your shell path. To uninstall MacPython, you can simply remove these three things. A symlink to the Python executable is placed in /usr/local/bin/.

(Bold emphasis mine.)

I believe I have uninstalled older pythons by dragging and dropping the python x.y folder from Finder into the trashcan.

Thanks Karl (and Terry). Yeah I was running 3.7 and I kept adding the pygame module in the 3.6 path. I installed 3.12 and everything works fine at least for now. Still trying to figure out the virtual environments.

Just doing sudo rm -rf /Library/Frameworks/Python.framework should work :slight_smile:
But sudo rm /usr/bin/python* may not workā€¦
Permissions for /Library/Frameworks and /Applications are usually both the same (ā€˜rootā€™ as user and ā€˜wheelā€™ or ā€˜adminā€™ as group). /usr/bin/python3 has extra protectionsā€¦
As others said, better just leave that alone.

WILL not work. As I said Appleā€™s macOS makes the OS files like all of /usr read-only and very hard to make writeable. macOS is an immutable OS. Its system volume is protected by the kernel to keep it immutable.

Strictly speaking MacOS is not an ā€œimmutable OSā€ - otherwise security patches (and kernel extensions developed by a user) would not be installable for instance.
You have to go through a few hoops (and reboots) to make modifications in /usr/bin and itā€™s generally not a good idea to make any modifications in that directory, but it is possible. SIP can be disabled (see: Disabling and Enabling System Integrity Protection | Apple Developer Documentation), and you can select a security policy that allows user management of programs in that directory.

Update: Though it is possible to delete files or modify them (in recovery mode), after a reboot (on Sonoma), they are restored. So, itā€™s not as easy as I thought. Since they must be restored from some snapshot, there must be a way around this, but I donā€™t know what that is.