Create new conda environment in google colab

I am in trouble while switching to my new env using colab. I successful created the env ‘new_env’ by

1
!conda create -n new_env python==x.x

and through

1
!conda env list

which prints

1
2
3
4
# conda environments:
#
base /usr/local
new_env * /usr/local/envs/new_env

I am sure I made it.

However, i can not use this new env. And finally, i find that

1
2
!source activate new_env && conda env list
!conda env list

will print

1
2
3
4
5
6
7
8
9
10
# conda environments:
#
base /usr/local
new_env * /usr/local/envs/new_env

# conda environments:
#
base * /usr/local
new_env /usr/local/envs/new_env

and

1
2
3
%%bash
source activate new_env
conda env list

will print

1
2
3
4
# conda environments:
#
base /usr/local
new_env * /usr/local/envs/new_env

So, I realize that either should i add ‘source activate new_env &&’ before all bash commands or use ‘%%bash’.

By the way, it is even harder to install environment.yml in base environment.