Specific reasons to favor pip vs. conda when installing Python packages
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.
This is what I do:
- Activate your conda virutal env
- Use pip to install into your virtual env
- If you face any compatibility issues, use conda
I recently ran into this when numpy / matplotlib freaked out and I used the conda build to resolve the issue.
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 afterconda
- install as many requirements as possible with
conda
, then usepip
- pip should be run with
--upgrade-strategy "only-if-needed"
(the default)- Do not use
pip
with the--user
argument, avoid all “users” installsUse 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] environmentRecreate the environment if changes are needed
- once
pip
has been usedconda
will be unaware of the changes- to install additional Conda packages it is best to recreate the environment
Store
conda
andpip
requirements in text files
- package requirements can be passed to
conda
via the--file
argumentpip
accepts a list of Python packages with-r
or--requirements
conda env
will export or create environments based on a file withconda
andpip
requirements