Python Packages – Using Pip vs. MacPorts for Installation

installmacportspackage-managementpython

I could install a python package (for example, numpy) on my Mac either via Macports:

port install py-numpy

or via pip:

pip install numpy

What are the general pros/cons of each approach? When should each approach be used?

  • When should I prefer one over the other?
  • Does it matter whether the package I'm installing is small or large (e.g. numpy)?
  • Does it depend on the version of python I'm using (2.x vs. 3.x, or Apple's python vs. MacPort's python)?
  • Does it matter whether I have multiple versions of python installed on my Mac?
  • Can they be used concurrently?

I'm hoping for an answer that has a short listing of some pros/cons of each approach with some discussion about when to choose one over the other.

Best Answer

They can be used concurrently, and there should be no issue between mixing the two (with one kinda big caveat and a gotcha...)

The Caveat

The caveat is that macports/homebrew and pip will have no awareness of each has installed vs the other.

So, for example, lets say you install python 3.6 on your Mac. You want nltk, which is not technically available for that version on Macports, but it is on pip. So you install on pip. Two months later, you see its installed on Macports and choose to install it. Now you have two different versions of nltk on your machine, so caveat emptor.

The Gotcha

If you do use pip with Macports, you need to make sure that it's the pip that is installed through Macports and associated with that python version. So, for example, you will see a py35-pip, py36-pip, etc.

Once you install the proper pip, you use Macports's select command to make sure that it's activated with the appropriate version of python:

sudo port select