简体   繁体   中英

When can I use “conda install” and when have to use “pip install”

I am trying to use conda to manage the environment. Most of the time, I can simply do conda install foo instead of pip install foo . However, in some cases (happens rarely), conda install foo can run into PackagesNotFoundError error. Why is that?

This is a concrete example. conda install pygal works fine. However, one of its optional dependency pygal_maps_world (for map support), won't be able to install via conda directly.

$ conda install pygal_maps_world

Solving environment: failed

PackagesNotFoundError: The following packages are not available from current channels:

  - pygal_maps_world

Current channels:

  - https://repo.anaconda.com/pkgs/main/osx-64
  - https://repo.anaconda.com/pkgs/main/noarch
  - https://repo.anaconda.com/pkgs/free/osx-64
  - https://repo.anaconda.com/pkgs/free/noarch
  - https://repo.anaconda.com/pkgs/r/osx-64
  - https://repo.anaconda.com/pkgs/r/noarch
  - https://repo.anaconda.com/pkgs/pro/osx-64
  - https://repo.anaconda.com/pkgs/pro/noarch
  - https://conda.anaconda.org/conda-forge/osx-64
  - https://conda.anaconda.org/conda-forge/noarch

To search for alternate channels that may provide the conda package you're
looking for, navigate to

    https://anaconda.org

and use the search bar at the top of the page.

I tried pip install pygal_maps_world based on http://www.pygal.org/en/stable/documentation/types/maps/pygal_maps_world.html . And then the exportd ymal file looks like this:

name: foo_env
channels:
  - defaults
  - conda-forge
dependencies:
  - ... some other libraries
  - zlib=1.2.11=h1de35cc_3
  - zstd=1.3.7=h5bba6e5_0
  - pip:
    - pygal-maps-world==1.0.2

Look at the bottom ^^^, it added a - pip session. Why is that? How do we find out which library can be installed via conda directly and which one of them needs to go through pip ?

As laid out in the Understanding Conda and Pip page for Anaconda, Conda and Pip install from different repositories.

Pip installs Python software packaged as wheels or source distributions.
...
Conda is a cross platform package and environment manager that installs and manages conda packages from the Anaconda repository as well as from the Anaconda Cloud. Conda packages are binaries.

If you want to manually verify beforehand, you can peruse the repositories .

Or, if you're installing requirements programmatically, you can wrap your conda install in a try/except block and on PackagesNotFoundError try a pip install instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM