乐闻世界logo
搜索文章和话题

How do I install pip on macOS or OS X?

1个答案

1

Installing pip (Python's package installer) on macOS or OS X can be done in several ways. Below, I will detail the common methods.

Using the System's Built-in Python to Install pip

macOS versions prior to Catalina typically included Python 2 pre-installed, but starting with macOS Catalina, Python is no longer pre-installed on the system. If your system already has Python, you can install pip using the following command:

  1. Open Terminal (available in the 'Others' folder of Launchpad).
  2. Enter the following command to install pip:
bash
sudo easy_install pip

This method uses easy_install, a module from the setuptools package, which can also be used to install Python packages.

Installing pip Using the Official get-pip.py Script

If your system does not have Python pre-installed, or if you need to install pip for Python 3, follow these steps:

  1. First, ensure Python is installed on your system. You can check this by entering python3 --version in the Terminal.
  2. Download the get-pip.py installation script from the pip official website.
  3. Run the following command in the Terminal:
bash
python3 get-pip.py

This will install pip and typically also install wheel, a tool for building Python packages.

Installing Python and pip via Homebrew

Homebrew is a package manager for macOS that can be used to install and manage software packages. If you haven't installed Homebrew yet, run the following command in the Terminal to install it:

bash
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

After installing Homebrew, you can install Python using Homebrew, which will also install pip. Run the following command in the Terminal:

bash
brew install python

This command will install the latest version of Python and pip.

Verifying the Installation

Regardless of the method used to install pip, you can verify the installation with the following command:

bash
pip --version

Or for Python 3:

bash
pip3 --version

The above are the common methods for installing pip on macOS or OS X.

2024年7月23日 16:37 回复

你的答案