Install Conda and friends on Google Colab, easily
Project description
condacolab
Install Conda and friends on Google Colab, easily.
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_miniconda(): This will install the Miniconda distribution, using a version built for Python 3.11. Unlike Anaconda, this distribution only containspythonandconda.install_miniforge(): Like Miniconda, but built offconda-forgepackages. The Miniforge distribution is officially provided by conda-forge.
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.11 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
baseenvironment, 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>.
FAQ
How does it work?
Google Colab runs on Python 3.11. 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.11 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
constructorinstaller on Colab too! Follow this tutorial.
Locally, follow these steps:
- 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
- Add your
condapackages toconstruct.yamlin thespecssection. Read the comments to respect the constrains already present! You can also adapt the metadata to your liking. - If you do need to install
piprequirements, uncomment thepost_installline and editpip-dependencies.sh. - Run
constructor --platform linux-64 . - Upload the resulting
.shto an online location with a permanent URL. GitHub Releases is great for this! - 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file condacolab-0.1.10.tar.gz.
File metadata
- Download URL: condacolab-0.1.10.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.0.1 CPython/3.13.1 Darwin/24.2.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bb435f3b674e43f9145964265cd6a25a1eeb117333030ccdc4a601c0c1a282f6
|
|
| MD5 |
368f8c048e5ced876e49f15d5ecc52ad
|
|
| BLAKE2b-256 |
377151749f43864738a3c12fc85d047da05bd35166239208841bda4afb2597d7
|
File details
Details for the file condacolab-0.1.10-py3-none-any.whl.
File metadata
- Download URL: condacolab-0.1.10-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.0.1 CPython/3.13.1 Darwin/24.2.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7f2ae042f57e53b075824eeed9c40990effeacf985e849c31b39e701c488fa62
|
|
| MD5 |
d2a03a7d6159a5737acc4dc46c435dd0
|
|
| BLAKE2b-256 |
8b24f6101ae9af9c2489a0c4eaea447292d1e7eea65c90544268041416d19208
|