- How to Uninstall Packages with Homebrew. If you have installed Homebrew on a Mac to use as a package manager for various unix and command line utilities, you’ve probably also installed a handful of packages deemed useful to you.
- We only use Anaconda for the convenience of installation of Python and the main packages, not the other stuff that comes with it as well. Homebrew (Mac only) If you want a bit more control over your Python distribution, then using Homebrew to install Python is useful. It also installs the package manager pip for you, which is very useful.
Anaconda is a package manager, an environment manager, and Python distribution that contains a collection of many open source packages. An installation of Anaconda comes with many packages such as numpy, scikit-learn, scipy, and pandas preinstalled and is also the recommended way to install Jupyter Notebooks. Installing anaconda on a macOS is not a simple task. Sometimes it requires a lot of troubleshooting, like setting the right shell initialization. To solve this I propose to install anaconda through homebrew. All of these commands are performed through the terminal unless otherwise specified in step 3.
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.
Cask anaconda installs files under $ (brew -prefix). The presence of such files can cause warnings when running `brew doctor`, which is considered to be a bug in Homebrew Cask.
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.Windows Install Conda
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 (
[email protected]
).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:
/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
27 Apr 2016'python'
formula are bottled against Homebrew’s Python 3.x and require it to be installed.Using Python Anaconda with iGraph
Anaconda’s all-included distribution is a great way to simplify the setup and management of Python installations for new users. Occasionally, the libraries bundled with Anaconda take priority over the default or Homebrew versions and cause issues when building extensions. I ran into this issue while trying to install python-igraph on a clean install of OS X 10.11, with homebrew installed igraph C library and Anaconda Python 2.7.
The symptoms
Upon
pip install python-igraph
I was getting errors:After forcing Anaconda from the path, I was able to get a successful build but could not
import igraph
in the python console:A solution
I read suggestions to uninstall various components, rename library files and other solutions that do not pass the system admin smell test. I wanted a solution that left the installations alone and used the components I specified. These steps resulted in a working python-igraph installation that passed the
igraph.test
test suite.1.
Temporarily change your PATH to avoid anaconda directories.2.
Try this first if you think brew igraph install is messed up:3.
Install homebrew iGraph normally:or if you don’t have homebrew/science/ tapped,
4.
Use extra flags so python-igraph is not built against the libraries bundled with Anaconda: