Hi, please help me I’m already stuck on this 2 days.
Ok it is as follows: I have a MacBookPro 2019, I deleted everything what has to do with Python on my computer via downloads and then searching on python. I am afraid I deleted the standard version of Python which comes automatically on your Mac. Now, I cannot install pip and Python again. Someone has tips on how to solve. ‘python --version’ gives me a message ; ‘Python is not defined’ and ‘python -m pip install -U pip’ gives me an invalid syntax. ‘Pip install pandas’ gives me also an invalid syntax. How to solve this and fix my python ??? Thanks if you could help.
Don’t Macs automatically run backups of your system? Something called
Time Machine, I think?
Can you restore the lost Python files from Time Machine, and then be
more careful about only deleting your installed Python, and not the
system Python.
Otherwise, can you run the Mac installer and re-install the missing
Python packages? Or is there a system repair tool you can use?
You may have to ask Mac specialists how to fix this.
From the error message, it looks like you are typing python --version and pip install -U pip at the Python prompt, and not at the system command prompt.
Let me explain a bit. (Apologies if you already knew, it’s hard to judge that.)
The system prompt, which usually ends with a $, is used to run commands like python --version or python -m pip:
If you run just python, without arguments, you’ll enter Python’s interactive mode (REPL), where the prompt changes to >>> and where you can enter Python commands, but not the system commands:
$ python
Python 3.9.1 (default, Dec 8 2020, 00:00:00)
[GCC 10.2.1 20201016 (Red Hat 10.2.1-6)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 1 + 1
2
>>> python --version
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'python' is not defined
The way back is to call exit(), which will exit the REPL and put you back to the system command prompt:
>>> exit()
$
It’s also possible that you’re starting Python directly, and exit() will close the window instead of take you to the system command prompt. In that case, you need to use the system command prompt instead. (I hear it’s under Applications → Utilities → Terminal, but I’m not personally familiar with Mac.)
Thank you all! I managed to fix it. I restarted my Mac to Factory Settings and then Python 2.7 was again present. Thanks a lot for ypur thinking and responses and happy christmas.