Can I install packages from specific channels when using PIP as it's possible in Anaconda?

8,305

Solution 1

pip supports specifying additional repositories to look for packages; these behave similarly to channels in conda<4. Example:

$ pip install somepkg --extra-index-url http://myindex.org

Multiple additional indexes can be specified in pip.conf:

[global]
extra-index-url=
    http://myindex.org
    http://other-index.org
    http://third-index.org

When an index is provided via extra-index-url, pip will always search the default index at https://pypi.org, then the extra index and install the first matching package. Overriding http://pypi.org is also possible, via

$ pip install --index-url http://myindex.org

hosting a local index

It's actually pretty easy to host a local index if you need one. Although there are a lot of third-party PyPI servers available (to name a few: devpi, wheelhouse or pypiserver), you need nothing besides a Python installation to fire up one yourself. Create a directory with subdirs named same as packages and containing the installation files:

repo
└── MyPackage
     └── MyPackage.tar.gz

Navigate to the directory and run the stdlib's server:

$ cd repo/
$ python -m SimpleHTTPServer 9000

Now you can install the packages from your local repository:

$ pip install MyPackage --extra-index-url = http://127.0.0.1:9000/

Solution 2

If I am not mistaken, I believe that pip doesn't have "channels" in the same way that Anaconda does. Essentially, pip assumes that for simple online installs (e.g. pip install package_name), it will be pulling from PyPI.

That said, regardless, it certainly is possible to pull from other sources (both local and remote) — see the official Python installing packages guide for some examples. Supported sources can include version control systems (VCSs), alternate Indexes (i.e. not PyPI), local src tree, and local archives/wheels.

More VCS support documentation for Git, Mercurial, Subversion and Bazaar can be found here.

Share:
8,305

Related videos on Youtube

Daniel Möller
Author by

Daniel Möller

Getting into neural networks :)

Updated on September 18, 2022

Comments

  • Daniel Möller
    Daniel Möller over 1 year

    In Anaconda, there is the option of adding "channels" to the configuration files.

    Every package installed with conda install ... will first look for packages in these channels (such as the intel channel, for instance).

    Is there a way to make PIP also install from specific channels?

  • Daniel Möller
    Daniel Möller almost 6 years
    This is very very probably the answer, but how could I find the url for the channels used by anaconda? For instance, there is the intel channel (and only that, no address, no easy info on the internet)
  • hoefling
    hoefling almost 6 years
    I'm not much into conda, but AFAIR conda info should at least print all the URLs of channels used, but no name mapping.