Question

Specific reasons to favor pip or conda for installing Python packages

I use miniconda as my default python installation. How can I choose between using Conda and Pip to install a package? That is, what objective factors would suggest using one or the other for a specific installation?

Normally I install everything with pip, and only use conda if a package is not available through pip or the pip version doesn't work correctly.


See also: Is it a bad idea to use conda and pip install on the same environment?

 46  25058  46
1 Jan 1970

Solution

 28

I find I use conda first simply because it installs the binary, than try pip if the package isn't there. For instance psycopg2 is far easier to install in conda than pip.

https://jakevdp.github.io/blog/2016/08/25/conda-myths-and-misconceptions/

Pip, which stands for Pip Installs Packages, is Python's officially-sanctioned package manager, and is most commonly used to install packages published on the Python Package Index (PyPI). Both pip and PyPI are governed and supported by the Python Packaging Authority (PyPA).

In short, pip is a general-purpose manager for Python packages; conda is a language-agnostic cross-platform environment manager. For the user, the most salient distinction is probably this: pip installs python packages within any environment; conda installs any package within conda environments. If all you are doing is installing Python packages within an isolated environment, conda and pip+virtualenv are mostly interchangeable, modulo some difference in dependency handling and package availability. By isolated environment I mean a conda-env or virtualenv, in which you can install packages without modifying your system Python installation.

If we focus on just installation of Python packages, conda and pip serve different audiences and different purposes. If you want to, say, manage Python packages within an existing system Python installation, conda can't help you: by design, it can only install packages within conda environments. If you want to, say, work with the many Python packages which rely on external dependencies (NumPy, SciPy, and Matplotlib are common examples), while tracking those dependencies in a meaningful way, pip can't help you: by design, it manages Python packages and only Python packages.

Conda and pip are not competitors, but rather tools focused on different groups of users and patterns of use.

2019-02-22

Solution

 22

Note: The following recommendations are now part of the official documentation.


"What is the current (2019) wisdom regarding when to install something with conda vs. pip?"

Anaconda Inc's Jonathan Helmus sums this up quite nicely in the post "Using Pip in a Conda Environment." Here's an excerpt from the final best practices recommendation:

Best Practices Checklist

Use pip only after conda

  • install as many requirements as possible with conda, then use pip
  • pip should be run with --upgrade-strategy "only-if-needed" (the default)
  • Do not use pip with the --user argument, avoid all “users” installs

Use Conda environments for isolation

  • create a Conda environment to isolate any changes pip makes
  • environments take up little space thanks to hard links
  • care should be taken to avoid running pip in the root [base] environment

Recreate the environment if changes are needed

  • once pip has been used conda will be unaware of the changes
  • to install additional Conda packages it is best to recreate the environment

Store conda and pip requirements in text files

  • package requirements can be passed to conda via the --file argument
  • pip accepts a list of Python packages with -r or --requirements
  • conda env will export or create environments based on a file with conda and pip requirements
2019-09-06