Help! The Package I Want Isn't on Anaconda Cloud

Don’t panic! There’s probably a way to fix this problem. First figure out how else your package is available (e.g. through pip, CRAN, or a Git repo). Then, follow the steps below…

The package can be installed with pip, but not Conda

This can be fixed with a simple modification to the environment.yml file. Conda will install pip into your environment, and can then instruct pip to install other packages. This is achieved by listing the desired pip packages in an indented manner underneath pip: in the environment.yml file:

name: test-env 
dependencies:
- python>=3.5   
- anaconda
- pip
- pip:     
  - package1
  - package2

Alternatively, if you can also list the pip dependencies in a separate requirements.txt file:

name: test-env 
dependencies:
- python>=3.5   
- anaconda
- pip
- pip:     
  - -r file:requirements.txt

Remember that if you want to add new Conda packages to this environment, you should recreate the environment from scratch so that the Conda packages are always installed before the pip packages. If you have pip installed a package manually, conda env is smart enough to know this and include this in the environment.yml file when you conda env export > environment.yml.

The package can be installed with install.packages() in R, but not Conda

Sure, you could activate the environment, then install the package, but there’s two problems with this. First, it defeats the point of using a package manager in the first place. Conda is the overseer of your packages, but you’ve just let in a piece of software that it is completely oblivious to. This will probably break your environment at some point, because some package won’t have the dependencies it needs.

The second problem is when you export this environment, this unknown package won’t go with it. Note how this is different to the case of the package available through pip, which Conda can at least include in environment.yml. So say you want to give your friend your environment, or use it for a step of a Snakemake pipeline. That package that you didn’t install with Conda? It’s not gonna be in the .yml file, so it won’t make it into the environment when its reconstructed somewhere else.

Good news! There’s

conda skeleton cran package_name

This is essentially a command that let’s you create the files you need for a Conda package from an existing CRAN package. The output of this command will be directory containing a file called meta.yaml. This file contains the instructions for how to build the package, what dependencies it has, etc. Now if you execute

conda-build package_name

A binary file will be created. Then you can simply install this into your environment!

conda install --use-local package_name

Although a better course of action would be to upload it to Anaconda Cloud. Then other people can use it in the future, without having to do all of the above themselves. First, make sure you have an Anaconda Cloud account. Then simply run:

anaconda upload package_name.tar.bz2

Now you can install the package into your Conda environment the good old fashioned way.

conda install package_name

The package can be installed with R’s devtools::install_github(), but not Conda

Generally, such packages can still be made into Conda packages using conda skeleton cran because they tend to be laid out like CRAN packages. Then, see if you can make a skeleton of it by giving conda skeleton cran the URL of the Git repository.

conda skeleton cran github.com/author_username/package_name.git

Did you just get an error? If not, congrats! Follow the steps from The package can be installed with install.packages() in R, but not Conda and you’ll be fine!

If you did get an error, it is usually because the repository was not tagged. The error message will be long, but end with Error: no tags found if this is the case. This can be easily fixed. First, you’ll need to fork the Git repository then clone it to create a local copy of the code on your machine. Just execute:

git clone https://github.com/your_username/package_name package_name
cd package_name
git tag v0.0.0
git push --tags

Then continue on from The package can be installed with install.packages() in R, but not Conda.

References

https://github.com/conda/conda/issues/6674

https://stackoverflow.com/questions/35245401/combining-conda-environment-yml-with-pip-requirements-txt