Python accidentally deleted - Sonoma 14.2.1

I have accidentally deleted the some preinstalled Python 3.9 files from the system/library/framework. Is this a problem, and how/where can I recover these files?


Anyway, running python --version in the terminal yields Python 3.9.6.

MacBook Pro (M3, 2023)

Posted on Feb 13, 2024 11:02 AM

Reply
Question marked as Top-ranking reply

Posted on Feb 13, 2024 11:20 AM

I’m not sure why you were poking at /System/Library/Frameworks directory, or what else might have happened here, or why you might not have backups of whatever was deleted. Or if this was a change promulgated by Apple.


Did you remove anything at all? Or have you met the Python removal by Apple? Apple removed Python from macOS, and the Apple installed version of Python is only installed with Xcode (and the Python installed by Xcode is an old version, too).


In recent versions, Python is usually manually installed.


Best? Load Python from Python.org, and use that. I’d tend to avoid using the Homebrew Python here, and leave that to whatever dependencies might exist. Use the official Python distribution.


if you want to revert something that actually has changed (and I’m not sure there was anything here to get deleted), you can re-install macOS and re-install Xcode, which should restore what Apple has loaded. Have a complete and current backup first, of course.


It’s also possible this is all due to some stale PATH specification somewhere.

2 replies
Question marked as Top-ranking reply

Feb 13, 2024 11:20 AM in response to mrekrat

I’m not sure why you were poking at /System/Library/Frameworks directory, or what else might have happened here, or why you might not have backups of whatever was deleted. Or if this was a change promulgated by Apple.


Did you remove anything at all? Or have you met the Python removal by Apple? Apple removed Python from macOS, and the Apple installed version of Python is only installed with Xcode (and the Python installed by Xcode is an old version, too).


In recent versions, Python is usually manually installed.


Best? Load Python from Python.org, and use that. I’d tend to avoid using the Homebrew Python here, and leave that to whatever dependencies might exist. Use the official Python distribution.


if you want to revert something that actually has changed (and I’m not sure there was anything here to get deleted), you can re-install macOS and re-install Xcode, which should restore what Apple has loaded. Have a complete and current backup first, of course.


It’s also possible this is all due to some stale PATH specification somewhere.

Feb 13, 2024 11:27 AM in response to mrekrat

If you installed the command line tools for Xcode, it currently installs Python 3.9.6 — a quite old distribution as it is current release from Python.org is now officially up to Python 3.12.2. The 3.9 binaries and libraries are linked from your ~/Library/Python/3.9 folder to the /usr/bin location. Apple disabled the scripting bridge for this distribution.


I have the command line tools for Xcode installed, not for the crippled 3.9 distribution but for Swiftc and Clang compilation environments. To stay current with Python, I download the Universal2 installer for Python 3.12.2 from Python.org which has a proper macOS package installer. It creates an /Applications/Python 3.12 folder, installs the Library in /Library/Frameworks/Python.framework and links the Python3, idle3, pip3, etc binaries into /usr/local/bin.


To avoid running Python 3.9.6 from scripts, or from the command line, you alter your PATH statement in the shell dot file (e.g. .bash_profile, .zshrc) to this:


export PATH=".:/usr/local/bin:/Library/Frameworks/Python.framework/Versions/3.12/bin:${PATH}"



Once you have made that change and saved the dot file, do the following to make that take effect in the current Terminal session for the appropriate shell in use:


source ~/.zshrc
source ~/.bash_profile


Any additional Python packages that you install with pip3 will go into the following location:


/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/site-packages


This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Python accidentally deleted - Sonoma 14.2.1

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.