Skip to content

Create a Conda Package from a GitHub directory

Uyen Mai edited this page Aug 1, 2019 · 8 revisions

A Conda package is a software package uploaded onto Anaconda Cloud. It is readily for the Conda users to download and install via a simple conda install command. In this tutorial, we assume you have written a python package and uploaded it onto Github. Following the below instructions, you can create a Conda package and upload it to Anaconda Cloud. We will use the package TreeShrink as an example.

Install Anaconda

First, you need to download Anaconda and follow the instructions to install it.

Create a local directory for your package

On your local machine, create a directory for your package

mkdir treeshrink

Change to the created directory. Now you need to create 3 files for your package: meta.yaml, build.sh, and bld.bat.

Create meta.yaml

The file meta.yaml contains the meta data of your package. As an example, the meta.yaml for the package TreeShrink is as follow:

package:

name: treeshrink

version: 1.3.1

source:

git_rev: master

git_url: https://github.com/uym2/TreeShrink.git

requirements:

host:

  • python
  • setuptools

run:

  • python

test:

imports:

  • treeshrink

about:

home: https://github.com/uym2/TreeShrink

license: GNU GENERAL PUBLIC LICENSE

license_file: LICENSE

Create build.sh and bld.bat

Besides meta.yaml, 2 files are required for a build:

  • build.sh - Shell script for macOS and Linux.
  • bld.bat - Batch file for Windows.

These two files must be placed at the same directory as meta.yaml. The files contain the commands needed to install the package in the corresponding architecture. We will walk through the creation of these files for TreeShrink as a demonstration. As TreeShrink uses setuptools and it has the setup.py file included in the Github repository, one command needed to build TreeShrink is calling python to run setup.py. In addition, since TreeShrink uses the R package BMS, we must also include a command to build this package. As such, the build.sh for TreeShrink should be

R CMD INSTALL -l Rlib dependencies/BMS_0.3.3.tar.gz

$PYTHON setup.py install --single-version-externally-managed --record=record.txt # Python command to install the script.

Similarly, bld.bat for TreeShrink should contain the following two commands

R CMD INSTALL -l Rlib dependencies\BMS_0.3.3.tar.gz

if errorlevel 1 exit 1

"%PYTHON%" setup.py install --single-version-externally-managed --record=record.txt

if errorlevel 1 exit 1

Build and install the package

Use conda-build to build the package

conda-build treeshrink

When conda build is finished, it displays the package filename and location.

To install the package to your local machine, type

conda install --use-local treeshrink

Convert the packages to other platforms

Upload the package to Anaconda cloud

Locate the uploaded packages

https://anaconda.org/uym2/treeshrink