MacOS Catalina的Terminal安装pip方法及命令报错问题咨询
1. Installing pip on macOS Catalina
macOS Catalina comes with Python 2.7 pre-installed, which includes an older version of pip by default. But since you mentioned downloading the latest Python 3, let's focus on the recommended setup for that:
If you installed Python 3 from python.org:
The official installer should automatically set uppip3(the Python 3-specific version of pip) alongside Python. To confirm it's installed, run this in your Terminal:pip3 --versionIf for some reason it didn't install automatically, you can add it manually with this command:
curl https://bootstrap.pypa.io/get-pip.py | python3For Python 2 (not recommended, as it's end-of-life):
You can update the built-inpipusing:sudo pip install --upgrade pipBut I strongly suggest sticking with Python 3 since Python 2 no longer receives security updates.
2. Fixing "syntax incorrect" errors when running Terminal commands
This is a super common gotcha! That error almost always means you're typing shell commands inside the Python interactive interpreter, not directly in the Terminal's main shell (bash or zsh). Here's how to fix this:
- First, check your prompt: If you see
>>>instead of something likeyourname@yourmac ~ %, you're in the Python interpreter. - To exit the interpreter and return to the normal shell, type:
Or pressexit()Ctrl + Don your keyboard—either works. - Once you're back at the standard shell prompt, you can run commands like
pip3 --versionorpython3 --versionwithout syntax errors.
Quick tip: Type python3 only when you want to enter the Python environment to run code. For Terminal commands (like installing packages or checking versions), make sure you're back at the regular shell prompt first.
内容的提问来源于stack exchange,提问作者Artistic Withers

