Sometimes I need to install a pip-only package into a conda environment. If I install the package using pip install
, then all the dependencies for that package are installed using pip, even if they are available to conda.
I would like to install as many packages as possible through conda, so currently I use a hack to get the list of package dependencies through pip, search for all of them on conda, conda install
the ones that are found, and then go through with the pip install
.
Am I right to prefer installing dependencies through conda rather than pip? And if so, can anyone think of a more elegant way to solve this problem?
You can install pip in the current conda environment with the command conda install pip , as discussed in Using pip in an environment. If there are instances of pip installed both inside and outside the current conda environment, the instance of pip installed inside the current conda environment is used.
Conda provides many of the features found in pip, virtualenv, venv and pyenv. However it is a completely separate tool that will manage Python dependencies differently, and only works in Conda environments. Conda analyzes each package for compatible dependencies, and how to install them without conflict.
Because Conda introduces a new packaging format, you cannot use pip and Conda interchangeably; pip cannot install the Conda package format. You can use the two tools side by side (by installing pip with conda install pip ) but they do not interoperate either.
Whilst conda can not install files from GitHub directly, we can use conda to install pip, and (via pip) access GitHub. Whilst over 1,500 packages are available in the Anaconda repository, this is tiny compared to the over 150,000 packages available on PyPI.
pip and conda are two separate package managers. Only in very rare cases package managers actually work together. In practical applications conda and pip usually do not.
In reality, mixing conda and pip packages is usually unavoidable. This often leads to a messy package management, as you describe.
In my opinion, the best and currently only proper way to solve this problem is to create a conda package for all (pypi-)packages and dependencies you want to use in your conda environments.
conda-forge is a community effort that offers an easy way to contribute your own package to the conda infrastructure. You may want to check out if your package is already available, and if not if contributing is an option for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With