Homebrew Pip



Alternatively, since pgcli is a python package you can install it via the python package manager pip. There is also an older package manager known as easyinstall but it is replaced by pip. Check if pip is installed on the system. $ which pip If the above command returns an error, then you do not have pip. Without Homebrew you can install it like so: python3 - m pip install - user pipx python3 - m pipx ensurepath The pipx ensurepath command configures your shell to ensure it can find commands that have been installed by pipx - generally by making sure /.local/bin has been added to your PATH.

This page describes how Python is handled in Homebrew for users. See Python for Formula Authors for advice on writing formulae to install packages written in Python.

Homebrew should work with any CPython and defaults to the macOS system Python.

Homebrew provides formulae to brew Python 3.x.

Homebrew provided a python@2 formula until the end of 2019, at which point it was removed due to the Python 2 deprecation.

Pip install mac os

Important: If you choose to use a Python which isn’t either of these two (system Python or brewed Python), the Homebrew team cannot support any breakage that may occur.

Python 3.x

Homebrew provides a formula for Python 3.x (python@3.x).

Important: Python may be upgraded to a newer version at any time. Consider using a versionmanager such as pyenv if you require stability of minor or patch versions for virtual environments.

The executables are organised as follows:

  • python3 points to Homebrew’s Python 3.x (if installed)
  • pip3 points to Homebrew’s Python 3.x’s pip (if installed)

Unversioned symlinks for python, python-config, pip etc. are installed here:

Setuptools, Pip, etc.

The Python formulae install pip (as pip3) and Setuptools.

Setuptools can be updated via pip3, without having to re-brew Python:

Similarly, pip3 can be used to upgrade itself via:

site-packages and the PYTHONPATH

The site-packages is a directory that contains Python modules (especially bindings installed by other formulae). Homebrew creates it here:

So, for Python 3.y.z, you’ll find it at /usr/local/lib/python3.y/site-packages.

Python 3.y also searches for modules in:

Homebrew Pip3

  • /Library/Python/3.y/site-packages
  • ~/Library/Python/3.y/lib/python/site-packages

Homebrew’s site-packages directory is first created if (1) any Homebrew formula with Python bindings are installed, or (2) upon brew install python.

Why here?

The reasoning for this location is to preserve your modules between (minor) upgrades or re-installations of Python. Additionally, Homebrew has a strict policy never to write stuff outside of the brew --prefix, so we don’t spam your system.

Homebrew-provided Python bindings

Some formulae provide Python bindings.

Warning! Python may crash (see Common Issues) if you import <module> from a brewed Python if you ran brew install <formula_with_python_bindings> against the system Python. If you decide to switch to the brewed Python, then reinstall all formulae with Python bindings (e.g. pyside, wxwidgets, pygtk, pygobject, opencv, vtk and boost-python).

Policy for non-brewed Python bindings

These should be installed via pip install <package>. To discover, you can use pip search or https://pypi.python.org/pypi.

Note: macOS’s system Python does not provide pip. Follow the pip documentation to install it for your system Python if you would like it.

Brewed Python modules

For brewed Python, modules installed with pip3 or python3 setup.py install will be installed to the $(brew --prefix)/lib/pythonX.Y/site-packages directory (explained above). Executable Python scripts will be in $(brew --prefix)/bin.

The system Python may not know which compiler flags to set in order to build bindings for software installed in Homebrew so you may need to run:

Virtualenv

WARNING: When you brew install formulae that provide Python bindings, you should not be in an active virtual environment.

Activate the virtualenv after you’ve brewed, or brew in a fresh terminal window.Homebrew will still install Python modules into Homebrew’s site-packages and not into the virtual environment’s site-package.

Virtualenv has a --system-site-packages switch to allow “global” (i.e. Homebrew’s) site-packages to be accessible from within the virtualenv.

Why is Homebrew’s Python being installed as a dependency?

Formulae that declare an unconditional dependency on the 'python' formula are bottled against Homebrew’s Python 3.x and require it to be installed.

Question or issue on macOS:

I am using Mac OSX 10.8, previously I used macports, but I switched to brew.

So my question is easy.
Should I use brew or pip for installing matplotlib ?
Is there any difference and what ?

My goal is to have pandas, ipythone notebook and simpleCV up and running.

How to solve this problem?

Solution no. 1:

I recommend using a package manager (brew, indeed, or MacPorts). Here are a few reasons why:

  • If you use your package manager (MacPorts, brew,…) to later install additional programs that depend on Matplotlib, the package manager will install it regardless.

  • If you install a Python package via pip, and pip installs it in your package manager tree (MacPorts, brew,…), the package manager might complain. For example, MacPorts does not want to erase pip-installed packages, as a precaution, so compilation stops when MacPort detects that someone walked on its turf. The best way of installing Python packages is to first check if they are provided by your package manager, and then only install them with pip if they are not.

  • Compilation with pip sometimes fails where a package manager (MacPorts,…) has no problem: package managers are simply more powerful and general tools (they play nicely with required compiled libraries, for instance).

  • I would not recommend using a separate distribution of Matplotlib, for the same kind of reasons: any program from brew that depends on Matplotlib will install it anyway. Furthermore, if you instead want to install such a program without your package manager, it is generally hard to make it work with a specific distribution of Matplotlib (they might need libraries to be installed of top of it, etc.).

Pip

In summary, I would recommend to use one system for everything (brew, since this is what you chose), and pip for things that this system does not provide (just make sure that the pip you use corresponds to where you want things to go: your package manager’s Python library, with the right version, or the OS-provided Python,…). Multiplying tools and installs is too messy, in my experience, as various distributions/package managers/etc. are usually not meant to play well with each other.

Solution no. 2:

Homebrew Pipeline

Since you need compile many of these packages, it is not the simplest task on the Mac. I would recommend to use a distribution like Anaconda. It is free, comes with all the things you need and has a simple installer. It will save you a lot of hassle because all components work together.

Solution no. 3:

Brew does not have a clean matplotlib port; the port that brew search matplotlib finds is for python2, not python3.

However, Brew’s python3 installation recommends that pip3 be used to install python3 packages. This installs the Python3 packages into /usr/local/lib/python3.3/site-packages. I think that Brew’s approach may be better than MacPort’s, as with MacPorts I am constantly having MacPorts update python packages that don’t need to be updated, and it’s tracking of each python version independently of python is somewhat confusing to me.

However, pip3 now complains on installing matplotlib, saying that it is externally hosted which is a security vulnerability and will be disabled in the future.

Solution no. 4:

Edit: IMHO virtualenv and virtualenvwrapper have now been largely supplanted by the superb combination of pyenv and pipenv which combine to provide wonderfully isolated python version and dependency management. It makes it worth considering setting up dummy projects even if you want to just play around with various python packages. Dependencies are tracked stably and pipenv includes functionality for checking package updates and security issues. I’d highly recommend a switchover.

Consider managing your python packages in dedicated virtualenvs. You can install any non-python dependencies (freetype which is required by matplotlib) using Homebrew, but you may ultimately have fewer headaches managing your python packages using pip within a virtualenv

If you are using the system python, you can install matplotlib like so. I’m assuming you want to place the virtualenv at top level of your home directory, so the first line in the listing below may be different if you want to create the virtualenv elsewhere and you’ll need to adjust the remaining lines accordingly.

Homebrew Pip

If /usr/local/include/freetype2 exists but /usr/local/include/freetype doesn’t you will need to create a symlink from freetype2 to freetype to prevent errors when installing the matplotlib package

Finally, you can install matplotlib using pip.
pip install matplotlib

Any applications run from the previously created virtualenv will be able to import matplotlib.

Should you decide to use virtualenvs extensively, you may want to take a look at virtualenvwrapper which provide very nice functionality for managing multiple virtualenvs and switching between them.

Hope this helps!