How to cure Google Colab with miniconda installed and get on import ModuleNotFoundError?

Question:

I have used Google Colab for more than half a year successfully for a special application. In the beginning of my Colab-notebook script I install conda and use conda-forge for installing a key Python package. At the beginning of this year 2023 I became aware of the Colab update to use Ubuntu 20.04 LTS and made some updates of scripts and all worked again.

A few weeks ago, around 2023-03-09, something happened and the key package could still be imported and shows up using "!conda list", but the package cannot be imported. The error message is: ModuleNotFoundError: No module named….

I tested to install the package locally on a VBox VM with the same Ubuntu ver as Google Colab 20.04 and also same Python 3.8.16 and conda 23.1.0 version and works just fine.

So I guess the problem is with Gooble Colab and its environment, but what can be done?

Asked By: janpeter

||

Answers:

The reason to the problem is that Google Colab was updated to run Python 3.9 default, while before 3.8. The installation I had in my script was for Miniconda 3.8 version. That lead to a situation where my package of interest was installed in the wrong environment. Not all packages has this sensitivity to mis-match of Miniconda version but this package had!

Thus, important to have the Miniconda of the same Python version as the base environment.

Answered By: janpeter