55

I want to install pillow on my Mac. I have python 2.7 and python 3.4, both installed with Homebrew. I tried brew install pillow and it worked fine, but only for python 2.7. I haven't been able to find a way to install it for python 3. I tried brew install pillow3 but no luck. I've found a post on SO that says to first install pip3 with Homebrew and then use pip3 install pillow. As it happens, I have already installed pip3.

I've never understood the difference, if any, between installing a python package with pip and installing it with Homebrew. Can you explain it to me? Also, is it preferable to install with Homebrew if a formula is available? If installing with Homebrew is indeed preferable, do you know how to install pillow for python 3 with Homebrew?

The first answers indicate that I haven't made myself plain. If I had installed pillow with pip install pillow instead of brew install pillow would the installation on my system be any different? Why would Homebrew make a formula that does something that pip already does? Would it check for additional prerequisites or something? Why is there a formula for pillow with python2, but not as far as I can tell for pillow with python3?

Lumos
  • 570
  • 1
  • 11
  • 24
saulspatz
  • 5,011
  • 5
  • 36
  • 47
  • 11
    `brew` installs packages for *OSX*, `pip` installs packages for *Python*. – tzaman Sep 11 '15 at 19:10
  • 1
    try brew update command – SemperFi Sep 11 '15 at 19:11
  • 1
    @tzaman Thanks, but then why did `brew install pillow` work? I feel certain I've installed other python packages with brew, also. (Of, course, I may be hallucinating.) – saulspatz Sep 11 '15 at 19:15
  • 1
    @Catmandu Thanks, but it didn't work. – saulspatz Sep 11 '15 at 19:16
  • 2
    Here is a doc covering the suggested relationship between brew and pip: http://docs.brew.sh/Homebrew-and-Python.html – kmace Jan 10 '17 at 20:46
  • Great questions that are symbolic of the lack of 'plain English' documentation for users new to Python. Multiple versions, multiple package managers with dependencies on said versions, kernels, environment variables, etc. - it made my head spin so much I just learned R for data science. – psrpsrpsr Jul 31 '18 at 15:05

3 Answers3

62

well, packages for OSX may include packages for python.

pip is a packager for the python world - you should only ever be able to install python-things with it; homebrew is a package manager targetted at OSX; it doesn't impose any restrictions onto what software you can install with it - since python is a subset of software.

installing things with brew will install them into /usr/local/;

installing things with pip will fetch packages from the Python Package Index, and it will install them in a place where your python interpreter will find them: either into your home directory (e.g. ~/.local/lib/python2.7/site-packages/) or in some global search-path of your python interpreter (e.g. /usr/local/lib/python2.7/dist-packages/)

if you have installed the python interpreter via brew, then chances are high that any python-package installed via brew will be usable out of the box.

umläute
  • 28,885
  • 9
  • 68
  • 122
  • 1
    It look like `pip install pillow` put it in /Library/Python/2.7/site-packages/PIL which I think is the pre-installed python on the Mac, but `pip3 install pillow` put it in /usr/local/lib/python3.4/site-packages/PIL. – saulspatz Sep 11 '15 at 19:53
  • 2
    @saulspatz With latest Python from Homebrew, `pip install pillow` should install it in `$(brew --prefix)/lib/python2.7/site-packages` instead of in Apple Python. See `brew info python`. – Franklin Yu May 12 '17 at 04:35
5

Homebrew is a package manager, similar to apt on ubuntu or yum on some other linux distros. Pip is also a package manager, but is specific to python packages. Homebrew can be used to install a variety of things such as databases like MySQL and mongodb or webservers like apache or nginx.

pip install pillow should place the package in your PYTHONPATH whereas if you install it with brew, unless you've added the appropriate directories to your PYTHONPATH, python won't be able to import anything from it. If you're installing a python module, definitely use pip

wpercy
  • 9,636
  • 4
  • 33
  • 45
  • 2
    Thanks. What I meant to ask was, if I can install the package with either `brew install pillow` or `pip install pillow` are the end results any different? If so, is one way better than the other? I'll try to edit my question to make my meaning more plain. – saulspatz Sep 11 '15 at 19:20
  • 6
    `pip install pillow` should place the package in your PYTHONPATH whereas if you install it with `brew`, unless you've added the appropriate directories to your PYTHONPATH, python won't be able to import anything from it. If you're installing a python module, definitely use `pip`. – wpercy Sep 11 '15 at 19:23
  • 1
    That's what I need to know. Thanks. – saulspatz Sep 11 '15 at 19:29
1

I am also kind of confused about the differences between pip-installed vs. brew-installed python packages.

My understanding is that pip-installed package is not compiled for your specific system. It fetches the package from the the Python Package Index then compile and build it in your computer. Python package installed via homebrew is already built and compiled for your specific system (Macos). They should both work. But I am not sure whether packages installed from the two ways will be put in the same location.

For your questions about installing pillow via homebrew, I believe you should already done brew tap homebrew/python, because that's how you can install python packages from homebrew. On this github page they claim that

Formula are installed with Python 2 support by default. For simultaneous Python 3 support, use brew install <formula> --with-python3. If you don't need Python 2.x support at all, you can pass --with-python3 --without-python.

So try

brew install pillow --with-python3

or

brew install pillow --with-python3 --without-python

if you only want to install pillow for python3. You may need to do brew uninstall pillow first if homebrew warns you that pillow is already installed.

Lumos
  • 570
  • 1
  • 11
  • 24
Longwen Ou
  • 859
  • 4
  • 4