Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
878 views
in Technique[技术] by (71.8m points)

anaconda - conda environment in google colab [google-colaboratory]

I am trying to create a conda environmet in google colab notebook. I succesfully installed conda with the following comannd

!wget -c https://repo.continuum.io/archive/Anaconda3-5.1.0-Linux-x86_64.sh

!chmod +x Anaconda3-5.1.0-Linux-x86_64.sh

!bash ./Anaconda3-5.1.0-Linux-x86_64.sh -b -f -p /usr/local

Default python which is using by system is now Python 3.6.4 :: Anaconda, Inc.

I am trying to create an environment in conda by conda env create -f environment.yml

Every package got successfully installed but the problem now is that I am not able to activate this environment. I tried source activate myenv. but it also didn't worked.

After conda env list command I got two environments

base * /usr/local

myenv /usr/local/envs/myenv

Can anyone please help me how can I switch on to "myenv" environment? Any help will be very much appreciated.

Thanks In advance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can activate and run a new conda environment in Google Colab by using the magic %%bash command:

%%bash
source activate myenv

python
import sys
# some simple python commands
sys.path.append('/usr/local/lib/python3.6/site-packages')
print(sys.path)

print("Python version")
print(sys.version)

Also including a few other commands I needed to run to get my environment setup completely:

!conda update conda -y -q
!source /usr/local/etc/profile.d/conda.sh
!conda init 
!conda install -n root _license -y -q

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...