12

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.

3
  • Related, but too specific: stackoverflow.com/questions/16895282/…. I'm asking for general python packages rather than just matplotlib. – jvriesem May 5 '17 at 23:59
  • AFAIK these are already installed - you can check in terminal: > python and next command >import numpy as np and if no errors then you have it. Alternate solution is to use anaconda from continuum.io/downloads - has many features and further installations with pip will go in your anaconda folder. – Yoan May 6 '17 at 14:51
  • @Yoan: numpy is just an example. I'm asking about installation of packages in general. – jvriesem May 6 '17 at 21:30
3

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
1
  • 1
    My experience is that to install modules to the Python global area created by MacPorts causes conflicts. Sooner or later, MacPorts will try to install a port which you have already installed by pip. It will issue an error message about a file in that port being present but not installed by MacPorts. I think @IanC's answer is better: install to the global Python area using MacPorts only, install within virtual environments using pip only. – Jim DeLaHunt Oct 25 '19 at 9:35
5

You should use pip because it's the Python-native tool for managing package installations but you shouldn't pip-install things into your base Python installation. It can be a mess to have to sort out fixed version dependencies between multiple software repositories if you're pip-installing everything into your base Python installation on your machine.

Instead, you should pip-install virtualenv and then use it to manage different, virtual Python installations and all the associated pip-installed packages packages for each virtual environment.

This allows you to switch from working with, say, beautifulsoup 1.x in one software repository to beautifulsoup 2.x in another repository without having to wade through dependency management hell.

1
  • I used the Anaconda distribution of Python and it makes virtual environments a breeze. This uses conda as mentioned above. – Natsfan Jun 24 '20 at 18:31
0

I just did a quick test searching for the same package using Homebrew, MacPorts and pip3:

brew search numpy
sudo port search --name --glob '*numpy'
pip3 search numpy

MacPorts and pip3 had the same package (version 1.18.1), whereas Homebrew had version 1.16.

When collaborating with others, best to agree on how your development environments are configured or you'll start bumping into anomalies and getting different test results. Therefore, the best tool is the one you all agree on ;-)

0

In general use one package manager at a time.

Note things change the last time I really looked at setiups was 3 years ago, I don't think much has changed but pip etc does gain more functionality as time goes on.

Macports and Homebrew are general package managers for all languages. pip is a pure python one. There is also conda which is python but does some general purpose stuff as well. It seems to have expanded its scope to cover other languages.

pip (with pipenv) and conda also provide python virtual environments which basically allow different sets of libraries for each project and allows you to set a different version of python for each project. e.g. 2.7, 3.7 3.8 in the others you need to use version specific pip for python versions.

Another difference is in parts of a package that have non python dependencies. pip needs to compile those which the others will have a more robust compiler setup and usually will provide a compiled binary.

I think to install pip you need to bootstrap off macports or homebrew, the pipenv page shows homebrew. Just install python, pip and maybe pipenv from this package manager.

I now use conda as this seems to provide more and is self contained. I

Historically I used macports for the bootstrap and compile any C libraries e.g. numpy (some of the underlying maths packages have more tuning than pip does) and pip/pipenv for the pure python bits.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .