Package: condacolab
condacolabInstall Conda and friends on Google Colab, easily.UsageTLDR: Check theexample notebook here!On your Colab notebook, run the following code as thefirst executable cell:!pipinstall-qcondacolabimportcondacolabcondacolab.install()After the kernel restart, you can optionally add a new cell to check that everything is in place:importcondacolabcondacolab.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 defaultcondacolab.install()provides Mambaforge, but there are othercondadistributions to choose from:install_miniconda(): This will install the Miniconda distribution, using a version built for Python 3.10. Unlike Anaconda, this distribution only containspythonandconda.install_miniforge(): Like Miniconda, but built offconda-forgepackages. The Miniforge distribution is officially provided byconda-forge.install_mambaforge(): Like Miniforge, but withmambaincluded. The Mambaforge distribution is officially provided byconda-forge.For advanced users,install_from_url()is also available. It expects a URL pointing to aconstructor-like installer, so you can prebuild a Python 3.10 distribution that fulfills your own needs.If you want to build your ownconstructor-based installer, check the FAQ below!Once the installation is done, you can usecondaand/ormambato install the needed packages:!condainstallopenmm# or, faster:!mambainstallopenmmIf you have a environment file (e.g.environment.yml), you can use it like this:!condaenvupdate-nbase-fenvironment.yml# or, faster:!mambaenvupdate-nbase-fenvironment.ymlShortcomingsThe 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 thebaseenvironment, so do not try to create more environments withconda create. If you have an environment file, useconda env update -n base -f <your-file.yml>.FAQHow does it work?Google Colab runs on Python 3.10. 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.10 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-readLD_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 ownconstructor-based installer. We have provided an example inconstructor-example/construct.yaml.You can generate aconstructorinstaller on Colab too! Followthis tutorial.Locally, follow these steps:In your local computer:condacreate-nconstructor-cconda-forgeconstructor
condaactivateconstructor
mkdirmy-installercdmy-installer
curl-sLOhttps://raw.githubusercontent.com/jaimergp/condacolab/main/constructor-example/construct.yaml
curl-sLOhttps://raw.githubusercontent.com/jaimergp/condacolab/main/constructor-example/pip-dependencies.shAdd yourcondapackages toconstruct.yamlin thespecssection. Read the comments to respect the constrains already present! You can also adapt the metadata to your liking.If youdoneed to installpiprequirements, uncomment thepost_installline and editpip-dependencies.sh.Runconstructor --platform linux-64 .Upload the resulting.shto an online location with a permanent URL. GitHub Releases is great for this!In Colab, run:!pipinstall-qcondacolabimportcondacolabcondacolab.install_from_url(URL_TO_YOUR_CUSTOM_CONSTRUCTOR_INSTALLER)Can I install R packages?Yes, as long as you make sure you also installrpy2to overwrite Colab's installation.
Seeissue #26for more details.