How do I install pip on macOS or OS X?

2018-12-31 06:31发布

I spent most of the day yesterday searching for a clear answer for installing pip (package manager for Python). I can't find a good solution.

How do I install it?

21条回答
路过你的时光
2楼-- · 2018-12-31 06:45

NEW 2016 December: This worked for me on OS X v10.11 (El Capitan):

Mac comes with python 2, but not with pip.

Requirements

homebrew

Steps:

  1. curl -O https://bootstrap.pypa.io/get-pip.py

  2. sudo python get-pip.py

With this I got these errors (but I've solved them in step 3):

The directory '/Users/myuser/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.

The directory '/Users/myuser/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.

  1. pip install --upgrade pip

Finally you can install an app like:

  1. pip install couchapp

UPDATE: Python 3

If you install python 3, pip will be installed automatically.

brew install python3

You need only to upgrade pip, but before that you need create a virtual environment to work with Python 3. You can use a project folder or any folder:

python3 -m venv venv
source venv/bin/activate
pip install --upgrade pip

Check the versions:

pip -V
python --version

To deactivate the environment:

$ deactivate
查看更多
忆尘夕之涩
3楼-- · 2018-12-31 06:46

To install or upgrade pip, download get-pip.py from http://www.pip-installer.org/en/latest/installing.html

Then run the following: sudo python get-pip.py

For example:

sudo python Desktop/get-pip.py 
Password:
  Downloading/unpacking pip
  Downloading pip-1.5.2-py2.py3-none-any.whl (1.2MB): 1.2MB downloaded
Installing collected packages: pip
Successfully installed pip
Cleaning up...

sudo pip install pymongo
Password:
Downloading/unpacking pymongo
  Downloading pymongo-2.6.3.tar.gz (324kB): 324kB downloaded
  Running setup.py (path:/private/var/folders/0c/jb79t3bx7cz6h7p71ydhwb_m0000gn/T/pip_build_goker/pymongo/setup.py) egg_info for package pymongo

Installing collected packages: pymongo
...
查看更多
与君花间醉酒
4楼-- · 2018-12-31 06:47

If you want "pip3" you can do the ff:

via brew: brew install python3

enter image description here

then you can execute

pip3 <command> [options]

查看更多
不再属于我。
5楼-- · 2018-12-31 06:48

You can install it through Homebrew on OS X. Why would you install Python with Homebrew?

The version of Python that ships with OS X is great for learning but it’s not good for development. The version shipped with OS X may be out of date from the official current Python release, which is considered the stable production version. (source)

Homebrew is something of a package manager for OS X. Find more details on the Homebrew page. Once Homebrew is installed, run the following to install the latest Python, Pip & Setuptools:

brew install python
查看更多
公子世无双
6楼-- · 2018-12-31 06:48

I'm surprised no-one has mentioned this - since 2013, python itself is capable of installing pip, no external commands (and no internet connection) required.

sudo python -m ensurepip

This will create a similar install to what easy_install would.

查看更多
像晚风撩人
7楼-- · 2018-12-31 06:53

I recommend Anaconda to you. It`s the leading open data science platform powered by Python. There are many basic packages installed.

查看更多
登录 后发表回答