Skip to content

Using PyPi Packages with Conda

This tutorial describes how to copy a PyPi package over to the Binstar package index so you can easily use it in Conda environments. You can cut Binstar out of this process, but using Binstar allows you to conda install the package anywhere you like rather than keeping track of the tarball manually.

Why is this useful?

Python's package management is a known pain point, and it's especially acute for analytic packages that have C and FORTRAN dependencies. Conda has several advantages over the now-standard pip + virtualenv combination:

  • Package and environment management are handled by the same tool
  • Improved handling of environments with different interpreters
  • Provides binary, precompiled packages for your system (pip does not)

Conda is open source, but most useful when bundled in Continuum Analytics' Anaconda python distribution, which I've been using since Enthought killed EPD Free.

Continuum Analytics is happy to tell you about why they like Conda. Unfortunately, pip and Pypi integration doesn't work quite as well as they suggest:

  • conda install doesn't gracefully fall back on pip install
  • pip install within Conda environments doesn't really work
  • Conda is not as aware of pip as it should be
  • Conda uses a different package format than pip, so it can't use the Pypi repositories directly.

tl;dr: Conda/Anaconda are great, but they can't access everything on PyPi out of the box. How can we fix that? Read on!

Bringing a PyPi package to Conda

The process is pretty straightforward:

  1. Sign up with Binstar
  2. Build a Conda package from the PyPi package and upload to Binstar
  3. conda install as needed

Let's look at each step.

Sign up with Binstar

Create an account at https://binstar.org/. Accounts are currently free and open to the public without a beta code.

Create a .condarc file so Conda knows where to find your packages. The template is:

# This is a sample .condarc file
# a condarc file should be placed in $HOME/.condarc

channels:
  - defaults
  - http://conda.binstar.org/<username>

Build the Conda package

This can be complicated, but it usually isn't. As recommended on StackOverflow you can generally just:

conda skeleton pypi PACKAGE
conda build PACKAGE

If you want to take more control over this process, check out Continuum's collection of recipes on GitHub and read over Conda's build documentation.

During the build phase Conda will ask if you want to upload the package to Binstar. Say yes and provide your binstar login information. The package will be uploaded to your personal package index.

Install from Binstar

You can now install the package into any conda environment with conda install <package>. If you run into trouble, check conda info to make sure that your personal binstar url shows up under "channel URLs."If it doesn't, double-check your .condarc file.