Skip to main content

Install Conda and friends on Google Colab, easily

Project description

condacolab

Downloads Downloads Downloads

Install Conda and friends on Google Colab, easily.

CondaColab

Usage

TLDR: Check the example notebook here!

On your Colab notebook, run the following code as the first executable cell:

!pip install -q condacolab
import condacolab
condacolab.install()

After the kernel restart, you can optionally add a new cell to check that everything is in place:

import condacolab
condacolab.check()

It is important that you perform the installation first thing in the notebook because it will require a kernel restart, thus resetting the variables set up to that point.

The default condacolab.install() provides Mambaforge, but there are other conda distributions to choose from:

  • install_anaconda(): This will install the Anaconda 2022.05 distribution, the most recent version built for Python 3.7 at the time of update. This contains plenty of data science packages (link to current version docs).
  • install_miniconda(): This will install the Miniconda 4.12.0 distribution, using a version built for Python 3.7. Unlike Anaconda, this distribution only contains python and conda.
  • install_miniforge(): Like Miniconda, but built off conda-forge packages. The Miniforge distribution is officially provided by conda-forge but I forked and patched it so it's built for Python 3.7.
  • install_mambaforge(): Like Miniforge, but with mamba included. The Mambaforge distribution is officially provided by conda-forge but I forked and patched it so it's built for Python 3.7.

For advanced users, install_from_url() is also available. It expects a URL pointing to a constructor-like installer, so you can prebuild a Python 3.7 distribution that fulfills your own needs.

If you want to build your own constructor-based installer, check the FAQ below!

Once the installation is done, you can use conda and/or mamba to install the needed packages:

!conda install openmm

# or, faster:
!mamba install openmm

If you have a environment file (e.g. environment.yml), you can use it like this:

!conda env update -n base -f environment.yml

# or, faster:
!mamba env update -n base -f environment.yml

Shortcomings

  • The Python kernel needs to be restarted for changes to be applied. This happens automatically. If you are wondering why you are seeing a message saying "Your session crashed for an unknown reason", this is why. You can safely ignore this message!
  • You can only use the base environment, so do not try to create more environments with conda create.

FAQ

How does it work?

Google Colab runs on Python 3.7. We install the Miniconda distribution on top of the existing one at /usr/local, add a few configuration files so we stay with Python 3.7 (conda auto updates by default) and the newly installed packages are available. Finally, we wrap the Python executable to redirect and inject some environment variables needed to load the new libraries. Since we need to re-read LD_LIBRARY_PATH, a kernel restart is needed.

How can I cache my installation? I don't want to wait every time I start Colab.

The recommended approach is to build your own constructor-based installer. We have provided an example in constructor-example/construct.yaml.

You can generate a constructor installer on Colab too! Follow this tutorial.

Locally, follow these steps:

  1. In your local computer:
conda create -n constructor -c conda-forge constructor
conda activate constructor
mkdir my-installer
cd my-installer
curl -sLO https://raw.githubusercontent.com/jaimergp/condacolab/main/constructor-example/construct.yaml
curl -sLO https://raw.githubusercontent.com/jaimergp/condacolab/main/constructor-example/pip-dependencies.sh
  1. Add your conda packages to construct.yaml in the specs section. Read the comments to respect the constrains already present! You can also adapt the metadata to your liking.
  2. If you do need to install pip requirements, uncomment the post_install line and edit pip-dependencies.sh.
  3. Run constructor --platform linux-64 .
  4. Upload the resulting .sh to an online location with a permanent URL. GitHub Releases is great for this!
  5. In Colab, run:
!pip install -q condacolab
import condacolab
condacolab.install_from_url(URL_TO_YOUR_CUSTOM_CONSTRUCTOR_INSTALLER)

Can I install R packages?

Yes, as long as you make sure you also install rpy2 to overwrite Colab's installation. See issue #26 for more details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

condacolab-0.1.4.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

condacolab-0.1.4-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

Details for the file condacolab-0.1.4.tar.gz.

File metadata

  • Download URL: condacolab-0.1.4.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.7 CPython/3.9.5 Darwin/20.3.0

File hashes

Hashes for condacolab-0.1.4.tar.gz
Algorithm Hash digest
SHA256 8e5e7eace11bda4e040786d95775e48e53f096338e03ab31ebfbabf642805054
MD5 3d3964176f1720d550ea936e235f1cd1
BLAKE2b-256 911961a1985f0e7903dfd7e76215c39ba676373482feb7dd8c92f56f75417231

See more details on using hashes here.

File details

Details for the file condacolab-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: condacolab-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 6.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.7 CPython/3.9.5 Darwin/20.3.0

File hashes

Hashes for condacolab-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 98ba324d5fe8fe23444a6dae705319b2d3f96a1d34af53239e7e279410c47c66
MD5 66af36a612dd36512abb7ec47ee84ad3
BLAKE2b-256 465222d76b819dc45026f0930d010cdd4b1ddd9a2be2e8f0b77d1f3bb3b7d4f7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page