Skip to content

Creating Anaconda Binary Packages

Connie Gao edited this page Jul 18, 2016 · 12 revisions

You must begin with Anaconda with Python 2.7 installed. Then install conda-build and anaconda-client if needed:

conda install conda-build
conda install anaconda-client

Configure a .condarc file, which has the purpose of providing Anaconda settings and pointing to the rmg channel when looking for packages. The .condarc file should be stored either in the '~' folder (unix-based systems) or alternatively inside the base Anaconda installation folder (all systems).

The .condarc file should look like this:

channels:
  - defaults
  - rmg

Recently it has come to my attention that conda does not always prioritize the rmg channel's package. It instead finds the most optimal one. So you may have to force a version on your package if you want one specifically.

If you are using windows, you must install the conda package mingwpy:

conda install mingwpy

In Windows you may need to point distutils to MinGW. Go to C:\Anaconda or wherever you installed Anaconda, then type the following into the command prompt:

cd C:\Anaconda
echo -e "[build]\ncompiler=mingw32" > Lib/distutils/distutils.cfg

Creating RMG-related Binaries

Major Note: Make sure to make clean before doing any conda-build commands, because otherwise precompiled files may inflate the final package size of your anaconda binary.

For RMG-related source code to be compiled into a binary, first clone the repo (here we use the example PyDAS). Then in the directory outside of that repo and the same directory you did the cloning, type the command

cd ~/Code/
git clone https://github.com/ReactionMechanismGenerator/PyDAS/
conda build PyDAS

If the recipe is pre-made (such as from the conda-recipes repo http://github.com/ReactionMechanismGenerator/conda-recipes), you will not need to download the source code. You can compile the package by simply being in the parent directory of the recipe folder.

cd ~/Code/conda-recipes
conda build pydot

If successful, Anaconda will write that the build is successful in your terminal or command prompt and then tell you to upload it to a relevant channel.

The physical copy of the binary will be stored inside your anaconda folder here: ~/anaconda/conda-bld/linux-64 (replace linux-64 with the operating system you are using). When anaconda is trying to package, it creates a temporary environment in ~/anaconda/envs/_build to try to build and test the package. Going into the _build environment folder can sometimes help debug problematic binary builds.

Building Binaries for RMG Dependencies

In order for the Anaconda environment or the RMG-related binaries to work successfully, we compile and store all relevant dependencies on the RMG channel on Anaconda.org. Some of these recipes can be found in the conda-recipes repo: http://github.com/ReactionMechanismGenerator/conda-recipes

A larger repo of conda-recipes for a variety of packages can be found at http://github.com/conda/conda-recipes

For more information on how to create a build recipe or use one, scroll down to that section on this page.

Note: It is helpful to first search Anaconda.org or PyPI for anaconda or pip packages before trying to compile dependencies by yourself. Often there is a prebuilt package that you can copy to RMG's channel instead of having to build your own. Be sure to test them to see if they are working.

It is possible to copy a dependency from another channel to the RMG channel using the command

anaconda copy channelname/packagename/version --to-owner RMG

Currently this may be not working, and you can upload a package manually by first downloading it to disk and uploading the normal way.

Stylistically I recommend if you did not create the package yourself, to remove the OS prefix in front of the file and change it to just the pkgname_versionetc.tar.bz2 naming format so that it uploads and displays nicely.

Note that anaconda will automatically detect that the package is a conda package and also auto-detect the OS for while the package was built, so there is no need to specify it if the package is build properly.

Uploading, Testing, and Removing Packages from the Anaconda Channel

anaconda upload location_of_package/packagename_version_.tar.bz2

Alternatively if you are uploading to the RMG channel on Anaconda.org instead of your default user channel, use the flag -u:

anaconda upload location_of_package/packagename_version_.tar.bz2 -u RMG --force

Note that you will need to be an Admin or part of the RMG organization on Anaconda to upload to the RMG channel on Anaconda. The instructions for adding new organization owners can be found here.

The --force flag is optional for when you want to overwrite a package

To fully test the package after you upload it, run the command

conda create --name package_name_test_env package_name
source activate package_name

where package_name is replaced by whatever package you just built. This will create a fresh environment with only the single package on it. Then you can open a python prompt or type additional commands to test your package.

Make sure to check that the package is sourced from the package you just created by typing

source activate package_name_test_env
conda list

to verify the source of the package. If the source is not from your own channel or local compiled binary, you may need to clean the anaconda cache by typing the following to clean everything:

conda clean --all

To delete a malformed or deprecated package, use the command:

anaconda remove channelname/pkg/version

How to build a conda recipe

For more info visit the Conda documentation page here: http://conda.pydata.org/docs/building/recipe.html

Typically the recipe is a folder called pkg_name and contains the following files:

  • meta.yaml describes dependencies and tests for the package binary as well as OS specific flags

    • This typically just refers to a location where you can download the package source code from, such as a github, svn, or http location
    • In other cases, like with our RMG-Py or PyDAS code, we actually store these files along with the source code, and don't have to have a url for downloading the source code. You can still go outside the folder and build the package with the same command.
  • build.sh is the unix style build script

  • bld.bat is the windows style build script

You can build the package by going to the folder right outside pkg_name folder and typing the command

conda build pkg_name

Use the argument --no-include-recipe to not include the recipe in the finished binary, which includes most of the source files and could bloat the package size.

A list of conda ENVIRONMENT_VARIABLES can be used in all the recipe files to direct to the proper folders and binaries: a detailed list of these variables can be found at http://conda.pydata.org/docs/building/environment-vars.html