How to install PyPi packages using anaconda conda command

PythonPipAnacondaPypiConda

Python Problem Overview


When using the Anacoda Python distribution, what is the best way to install a PyPi package that isn't available directly through Anaconda? For now I'm using:

conda pipbuild [pypi_name]
conda install --use-local [package_spec]

But I'm unclear if this is the best way and if conda update --all will update these packages when updates are made available. I'm also unclear what the point of binstar is when PyPi already exists.

Python Solutions


Solution 1 - Python

I will disagree with the accepted response and note that pip install [some-pypi-package] is often the best way to install PyPi packages in Conda environments.

While the packages won't be managed by the Conda package manager, they will still be managed by the Anaconda environment. It will download the correct version of the package for the active Python install and update it correctly using the pip package manager.

When using Anaconda, you should turn to conda before pip when you can, but you don't lose any of the replicability benefits of using Anaconda when you use pip.

Anaconda recently published a doc that supports this: https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#using-pip-in-an-environment

Solution 2 - Python

If you want to build conda packages for PyPI packages, the recommended way is to use conda skeleton pypi package and use conda build package on the recipe that it creates. To install the package, use conda install --use-local package (here and elsewhere, package is the name of the PyPI package you wish to install).

You will need to update the recipe each time the package is updated.

You can also use pip to install these packages. There are two disadvantages: firstly, these packages won't be managed by conda at all. Secondly, these packages will not work if your default python version is different from the python version you are using in conda.

Solution 3 - Python

Since version 4.6.0, Conda has improved its interoperability with pip:

> Conda and pip have historically had difficulties getting along. Pip > hasn’t respected Conda’s environment constraints, while Conda has been > all too happy to clobber pip-installed software. It’s a mess. Conda > 4.6.0 adds preview support for better interoperability. With this interoperability, Conda can use pip-installed packages to satisfy > dependencies, and can even remove pip-installed software cleanly and > replace them with Conda packages when appropriate. There’s still room > for improvement before pip and Conda are hunky-dory BFFs, but we hope > this is a good start. This feature is disabled by default right now > because it can significantly impact Conda’s performance. If you’d like > to try it, you can set this condarc setting:

conda config --set pip_interop_enabled True

So, the way to get PyPI packages into conda (at the time of writing this) seems to be:

pip install <package>

If you want conda to replace the PyPI packages with its own (where possible), just run:

conda update --all

Given that the above setting is made. Conda marks its own channels as higher priority than pip, thus packages will be replaced.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser1507844View Question on Stackoverflow
Solution 1 - PythonChris ConlanView Answer on Stackoverflow
Solution 2 - PythonasmeurerView Answer on Stackoverflow
Solution 3 - PythonNichtJensView Answer on Stackoverflow