0

I uninstalled Python on my Mac by moving all python-related files in my Mac (including system files) to the trash and emptying the trash. Now, I can't get Python 3 to work at all (despite reinstalling it). How can I get all of the deleted Python files back?

Update: I deleted the following files:

/Applications/Python
/Library/Frameworks/Python.framework
/usr/local/bin/py

thon

  • If you had not put anything on the drive after you emptied the trash then maybe. I'd bet at least some of what you trashed has been overwritten and gone forever. – Steve Chambers Sep 18 '19 at 20:32
  • have you tried installing python using Anaconda? – jmh Sep 18 '19 at 21:18
  • 3
    Which python did you remove, the standard one installed as part of macOS, or a version you installed yourself? – nohillside Sep 19 '19 at 5:18
  • The answer deals with apples python but note that this is python 2.7. If you want python3 that is a different question. – mmmmmm Sep 19 '19 at 12:35
  • If it's an OS with SIP enabled, then I don't think you can delete the System python. – benwiggy Sep 19 '19 at 13:00
6

Ideally you can restore whatever you‘ve deleted from a backup.

If you removed the standard Python installation of macOS, boot into the Recovery Partition (if any) and reinstall macOS from there. This should leave your other files intact, it‘s not a bad idea to do a backup before nevertheless.

Alternatively, you can through Homebrew.

Once Homebrew is installed, run:

brew install python@2

That won't likely install the same 2.7 revision you were using.

If you need an exact match, or don't/can't use Homebrew; I'd build it from source (if so, comment for further instruction).

Python 2 is end of life by January 1st 2020. Please don’t use it unless you are sure you are using an OS default.


If I am not in mistake, as of June 2020 macOS 10.15.4 (i.e., not fully up to date) is still at Python 2.7 (2.7.16).

If you are at 10.15.5 or later you are welcome to comment your mileage.

| improve this answer | |
  • Which specific Mac model do you have if you assume it doesn‘t have a recovery partition? – nohillside Sep 19 '19 at 5:43
  • 1
    +1 for the first part but -1 for the second. You have no choice but to reinstall the Apple supplied python as parts of the OS depend on it e.g. /usr/bin/xattr (and Homebre python is not the best install of python) – mmmmmm Sep 19 '19 at 10:19
  • I agree with @Mark, may third-party software relies on specific python on specific macOS versions. – Eir Nym Sep 19 '19 at 10:28
  • @nohillside depending on an installation process (e.g. corporative installation) there could be no recovery partition. – Eir Nym Sep 19 '19 at 10:30
  • 2
    @EirNym In such a corporate environment the typical user also won't be able to delete the standard python installation (or, if they are able to, can just have the machine set up again by corporate IT) – nohillside Sep 19 '19 at 11:33
1
brew uninstall --ignore-dependencies python3

Then:

brew install python3

and done:

python3
| improve this answer | |
0

While restoring from a backup is always the best answer for recovering deleted files:

The files you list are not MacOS-bundled python components.

You should be able to download and run the Mac installer package from python.org directly:

https://www.python.org/downloads/

That should install everything necessary to use python3.

| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .