Becay
Becay

Reputation: 103

Running conda environments in Google Colab

Is it possible to run conda environments in google colab? I successfully installed conda and created an environment. But I get an error when trying to run the environment.

enter image description here

Upvotes: 2

Views: 9177

Answers (1)

Donald S
Donald S

Reputation: 1753

To run conda environments within google colab, you can use a %%bash magic line. Then you would have to run python again and execute your python commands. See below for example.

Example:

# activate your conda environment
%%bash
source activate myenv
python

# python commands are ready to run within your environment
import sys
print("Python version")
print (sys.version)
  • 1st line opens a "semi-permanent" bash shell
  • 2nd line activates your local environment
  • 3rd line goes back to a python executable
  • 4th line onwards are normal python commands

Upvotes: 5

Related Questions