Conda Channels are the the means of distributing entire repositories of conda packages. From a user point of viw, they are represented by file paths (http://, file://) that conda uses to search, find, download, and upload packges.
In this lesson, we'll see how to configure both local and external channels, how to create a custom channel, and how to spin up our own HTTP services to serve out conda packages.
- Installing from Channels
- Custom Channels
- Repository Channels
- Local Channels
- HTTP Serving Local Channels
- Exercise: Install from your HTTP Server
- Exercise: Have others Install from your HTTP Server
- Recap and Preview
- Conda packages are usually installed from channels, not just from local builds.
- Channels are the paths (URLS, really) that conda searches for packages.
- The easiest way to use channels is to use a private (Anaconda Repository) or public (
anaconda.org
) repository with pre-existing channels. - Custom channels can be constructed locally, and installed from using
file://
URLs, using just conda.
anaconda.org
is the default repository from which conda installs packagesdefaults
defines the default channels onanaconda.org
which conda searches when asked to install a package.- in the previous example we had to force conda to not look for
anaconda.org
- we used the
--use-local
flag to install the local constants package.
For example, if want to install
numpy
, runconda install numpy
. The numpy package file would be copied from from a channel calleddefault
that is hosted by Continuum Analytics atrepos.continuum.io
Recall the message that was seen at the end of a successful conda package build:
# If you want to upload this package to anaconda.org later, type:
#
# $ anaconda upload /Users/juser/anaconda/conda-bld/osx-64/constants-0.0.1-py35_0.tar.bz2
#
# To have conda build upload to anaconda.org automatically, use
# $ conda config --set anaconda_upload yes
This is very common way of sharing conda packages with the community of conda users. It first requires creating a account on anaconda.org
.
- uploading to anaconda.org personal account
- installing from anaconda.org personal account
- how your distant collaborators can also install from anaconda.org
The steps are as follows:
conda install anaconda-client
anaconda login
conda config --set anaconda_upload yes
anaconda upload $HOME/anaconda/conda-bld/osx-64/constants-0.0.1-py27_0.tar.bz2
Exercise: Install your package using anaconda.org
Install your recently uploaded package from anaconda.org using the following command:
conda install constants --channel <YOUR-ANACONDA-USERNAME>
You can use channels that are not the defaults on repositories like Anaconda Cloud or a private instance of Anaconda Repository.
To do so, you must add the channel to your conda figuration as follows:
conda config --add channels http://anaconda.org/<USERNAME>
You can create custom local channels as well.
While it is best to use Anaconda Cloud or Anaconda Repository, this example is useful in understanding how channels work.
This demonstration was developed and tested using conda 4.1.11
Preparing the local channel requires the following steps:
- find or build at least one conda package
- create a file tree for your channel:
- top level dir is the channel name
- sub-dirs for platform specific packages
- place your conda packages (files.tar.bz2) into the path
- run
conda index
on the platform sub-dirs
conda build my_recipe
mkdir /opt/my_channel/osx-64/
cd ~/anaconda/conda-bld/osx-64/
cp constants-0.0.1-py35_0.tar.bz2 /opt/my_channel/osx-64/
conda index /opt/my_channel/osx-64/
You can use conda convert
to add packages for other platforms to your local channel:
mkdir /opt/my_channel/win-64/
cd ~/anaconda/conda-bld/osx-64/
conda convert constants-0.0.1-py35_0.tar.bz2 -p win-64
cp win-64/constants-0.0.1-py35_0.tar.bz2 /opt/my_channel/win-64/
conda index /opt/my_channel/win-64/
After preparing your channel, test it with conda seach
:
conda search -c file://opt/my_channel constants --override-channels
Once prepared and tested, you are ready to install from your channel:
- create a new environment
- activate that environment
- install a package from your local channel with
conda install
- use
-c file://full_path_to_channel
- also use the
--override-channels
flag
- use
cd ~/
conda create -n test-local-channel python=3.5 ipython
source activate test-local-channel
conda install -c file://opt/my_channel constants --override-channels
You can even serve your local channels over HTTP:
Note: this is leading us to the capability that Anaconda Cloud and Anaconda Repository provide.
Update your ~/.condarc
by adding the IP address as shown:
channels:
- http://0.0.0.0:8000
- defaults
Use python to start an HTTP server:
Start the HTTP server from the directory that contains your indexed osx-64
and win-64
subdirs, so that they appear at the top level of the file tree served out:
cd ~/Desktop/my_channel
python -m http.server
Open a web browser to verify that you can see the directory contents, but crowsing to the following URL:
http://0.0.0.0:8000
TO install from this HTTP served channel, use conda install
and specifiy the <URL>:<PORT>
as the channel:
conda create -n test python=3.5
source activate test
conda install -c http://0.0.0.0:8000 constants
Using http://127.0.0.1:8000
in your ~/.condarc
and then install with conda install -c http://local.host constants
. Again, use a web browser and try to load http://127.0.0.1
to see if you get a file listing of the contents of my_channel
#~/.condarc
channels:
- http://127.0.0.1:8000
- defaults
Find you assigned IP address on the local network. For example, on Linux of Mac, in a terminal, run the ifconfig
command, and look for the value of inet
in the output block labeled en0
. Give that IP address to your classmate to your left, and ask them to run the commands above, but replace 0.0.0.0
or 127.0.0.1
with this new address. Does it work?
#~/.condarc
channels:
- http://10.0.32.184:8000
- defaults
conda create -n test-http python=3.5
source activate test-http
conda install -c http://10.0.32.184:8000 constants --override-channels
In this lesson we saw....
- Building a Conda package
- Installing a local conda package
- Installing packages from channels
- Uploading a custom conda package to anaconda.org
- Creating a custom local package channel
- Serving a local channel with a HTTP service