如何在Mac上为Python 3.6.4安装pip?现有方法均失效求助
Hey there, let's sort out this pip install mess for your Python 3.6.4 on Mac—your issues sound like a mix of using the wrong environment and incorrect commands, so let's break it down step by step.
First, let's fix the common mistakes you ran into:
- Why
get-pip.pythrew a syntax error: You probably tried running the script inside the Python interactive shell (the one with>>>prompts) instead of from the terminal. Thegetsyntax error happens because the shell thinks you're writing Python code, not executing a standalone script. - Why
aptandeasy_installfailed:aptis a Linux package manager—Mac doesn't use it at all! And when you saw commands with$, that's just the terminal's prompt symbol, not part of the actual command. You should always omit the$when typing commands into the terminal.
Now, let's try the reliable methods to install pip for Python 3.6.4:
Method 1: Use Python's built-in ensurepip (Most Recommended)
Python 3.4+ comes with a built-in tool to install pip directly. Open your terminal (not the Python shell) and run this command:
python3.6 -m ensurepip --upgrade
This tells Python 3.6 specifically to use its ensurepip module to install or update pip. If you hit a permission error, add --user to install it for your user account only (avoids needing sudo):
python3.6 -m ensurepip --upgrade --user
Method 2: Correctly run get-pip.py
If you still want to use the get-pip.py script, follow these steps:
- Make sure you've downloaded
get-pip.pyto an easy-to-access folder (like your Desktop). - Open Terminal and navigate to that folder:
cd ~/Desktop - Run the script using your Python 3.6 executable:
python3.6 get-pip.py
Again, add --user if you encounter permission issues:
python3.6 get-pip.py --user
Method 3: Use easy_install (Only if the above methods fail)
Mac's default easy_install is tied to Python 2, so you need to target Python 3.6 specifically. First, check if easy_install-3.6 is available:
easy_install-3.6 pip
If that command isn't found, call it via Python 3.6's module system:
python3.6 -m easy_install pip
Verify the installation worked
After trying any of these methods, confirm pip is installed for Python 3.6 by running:
pip3.6 --version
This should display the pip version linked to your Python 3.6.4 installation.
内容的提问来源于stack exchange,提问作者Tobias Woods

