According to the official Homebrew page:
On 1st March 2018 the python formula will be upgraded to Python 3.x and a python@2 formula will be added for installing Python 2.7 (although this will be keg-only so neither python nor python2 will be added to the PATH by default without a manual brew link --force). We will maintain python2, python3 and python@3 aliases.
So to install Python 3, run the following command:
brew install python3
Then, the or pip is installed automatically, and you can install any package by pip3.pip install <package>
brew install python3 but also brew postinstall python3So you must run:
brew install python3
brew postinstall python3
Note that you should check the console, as it might get you errors and in that case, the is not installed.pip3
TLDR. On any modern Mac python3 -m ensurepip
then to check.pip3 --version
pip's documentation lists the supported mechanisms to install it: https://pip.pypa.io/en/stable/installation/#supported-methods
It is generally recommended to avoid installing pip on the OS-provided commands, and to install Python via the official installers or using something like Homebrew or pyenv.python
Python 3.4+ will have , so if you're unable to run ensurepip -- run python3 -m pip and it'll install pip for you.python3 -m ensurepip
If you're using an end-of-life version of Python, you can use instead.get-pip.py
Old answer (outdated, and results in a broken installation)
easy_install pip
If you need admin privileges to run this, try:
sudo easy_install pip
The officially recommended python packaging tool is . One example of a workflow you could use to make a virtual environment with the exact libraries your project needs as well as ensuring security is this:pipenv
$ brew install pipenv
$ cd /path/to/project
$ pipenv --three
$ pipenv install opencv-python
And after you write your code in, say, project.py
$ pipenv run python3 project.py
More info on the pipenv site.
You could have multiple Python versions on your macOS.
You may check that by , command or type command, like:which
which -a python python2 python2.7 python3 python3.6
Or type in Terminal and hit Tab few times for auto completion, which is equivalent to:python
compgen -c python
By default /python commands points to the first binary found in pip environment variable depending what's actually installed. So before installing Python packages with Homebrew, the default Python is installed in PATH which is shipped with your macOS (e.g. Python 2.7.10 on High Sierra). Any versions found in /usr/bin (such as /usr/local) are provided by external packages./usr/local/bin
It is generally advised, that when working with multiple versions, for Python 2 you may use /python2 command, respectively for Python 3 you can use pip2/python3, but it depends on your configuration which commands are available.pip3
It is also worth to mention, that since release of Homebrew 1.5.0+ (on 19 January 2018), the formula has been upgraded to Python 3.x and a python formula will be added for installing Python 2.7. Before, python@2 formula was pointing to Python 2.python
For instance, if you've installed different version via Homebrew, try the following command:
brew list python python3
or:
brew list | grep ^python
it'll show you all Python files installed with the package.
Alternatively you may use or apropos command to locate more Python related files.locate python
To check any environment variables related to Python, run:
env | grep ^PYTHON
To address your issues:
Error: No such keg: /usr/local/Cellar/python
Means you don't have Python installed via Homebrew. However double check by specifying only one package at a time (like ).brew list python python2 python3
The locate database (
) does not exist./var/db/locate.database
Follow the advice and run:
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.locate.plist
After the database is rebuild, you can use command.locate