环境管理 - Conda Environment & Use conda in docker

让人想犯罪 __ 提交于 2019-12-15 12:19:31

In the last passage, we successfully download and install anaconda and pytorch. However, the one of the most important advantages to use conda instead of pip is its virtual enviroment, where you will have a clean enviroment isolated environment to focus on your experiment or development.

Generally, we often use python version 3.6 (Of course, you can use one version you are familar with). Then I wil show how to create Conda Environment, and activate environment in docker.

Create conda environment

conda create -n python3.6 python=3.6

Also, you can create both a python version2.7 and a python version3.6.

other useful conda commands

  • 列出所有的环境和当前环境(*)
    bash conda info --envs
  • 克隆环境从snowflakes到flowers
    conda create --name flowers --clone snowflakes
  • 删除环境flowers
    conda remove --name flowers --all

Enter docker

docker container ls

推荐使用docker exec,因为docker exec从终端退出的时候不会关闭终端,而docker attach

docker exec -it $docker_id bash 

Source and activate your env in docker

source miniconda3/bin/activate
conda activate python3.6
export CUDA_VISIBLE_DEVICES=0,1

Finally you can run your python script or conduct your exp anyway.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!