`conda` environments management

简介: conda

conda environments management :

cmds creating environments

you can create the environments firstly, and then install packages that all you needs. Or, you can create the environments and install packages simultaneously.

######################################################################
#create environments
$ conda create -n Newenv
#install packages
$ conda install -n Newenv python=3.6 scipy=0.15.0 astroid babel
########################################################################
#create environments and install packages simultaneously
$ conda create -n Newenv python=3.6 scipy=0.15.0 astroid babel
Install all the programs that you want in this environment at the same time. Installing 1 program at a time can lead to dependency conflicts.
environments.yml file creating environments
#environments.yml file creating environments `Newenv`. The first line of the `*.yml` file sets the new environment's name  
$ conda env create -f environments.yml
#activate 
$ conda activate myenv
#verify
$ conda env list
specify environments location

the default path maybe /home/username/miniconda/envs/Newenv. you can specify the location with cmd optionconda create --prefix ./Newenv python=3.6 scipy=0.15.0 astroid babel or conda create --prefix /home/username/.../Newenv python=3.6 scipy=0.15.0 astroid babel

#relative dir
$ conda create --prefix ./Newenv python=3.6 scipy=0.15.0 astroid babel
#absolute dir
$ conda create --prefix /home/username/.../Newenv python=3.6 scipy=0.15.0 astroid babel
#activate Newenv
$ conda activate ./Newenv
#activate and deactivate with absolute dir
[biocodee@localhost Pjt]$ conda activate /home/biocodee/Pjt/envs
(/home/biocodee/Pjt/envs) [biocodee@localhost Pjt]$ conda deactivate
#remove long prefix in shell prompt
$ conda config --set env_prompt '({name})'
[biocodee@localhost Pjt]$ conda activate ./envs
(envs)[biocodee@localhost Pjt]$ conda deactivate 
environment updating

you can update the contents of *.yml file accordingly and then run the following command :

#The `--prune` option causes conda to remove any dependencies that are no longer required from the environment.
$ conda env update --prefix ./env --file environment.yml  --prune
cloning environments

make an exact copy of an environment by creating a clone of it :

#myclone : the name of new environment. myenv: existing environment that want to copy 
conda create --name myclone --clone myenv
#verify 
$ conda info --envs
building identical conda environments

use explicit specification files to build an identical conda environment on the same operating system platform, either on the same machine or on a different machine. Conda does not check architecture or dependencies when installing from a spec file.

#1.produce a spec list 
[biocodee@localhost Pjt]$ conda list --explicit
# This file may be used to create an environment using:
# $ conda create --name <env> --file <this file>
# platform: linux-64
@EXPLICIT
https://repo.anaconda.com/pkgs/main/linux-64/_libgcc_mutex-0.1-main.conda
https://repo.anaconda.com/pkgs/main/linux-64/ca-certificates-2021.10.26-h06a4308_2.conda
https://repo.anaconda.com/pkgs/main/linux-64/ld_impl_linux-64-2.35.1-h7274673_9.conda
https://repo.anaconda.com/pkgs/main/linux-64/libstdcxx-ng-9.3.0-hd4cf53a_17.conda
https://repo.anaconda.com/pkgs/main/linux-64/libgomp-9.3.0-h5101ec6_17.conda
https://repo.anaconda.com/pkgs/main/linux-64/_openmp_mutex-4.5-1_gnu.tar.bz2
https://repo.anaconda.com/pkgs/main/linux-64/libgcc-ng-9.3.0-h5101ec6_17.conda
#create spec list as a file
[biocodee@localhost Pjt]$ conda list --explicit > spec-file.txt
[biocodee@localhost Pjt]$ ls -al
total 8
drwxrwxr-x.  7 biocodee biocodee   90 Dec 28 02:08 .
drwx------. 21 biocodee biocodee 4096 Dec 27 22:39 ..
drwxrwxr-x.  2 biocodee biocodee    6 Dec 27 21:08 data
drwxrwxr-x. 12 biocodee biocodee  184 Dec 27 23:10 envs
drwxrwxr-x.  2 biocodee biocodee    6 Dec 27 21:08 results
-rw-rw-r--.  1 biocodee biocodee 2896 Dec 28 02:08 spec-file.txt
drwxrwxr-x.  2 biocodee biocodee    6 Dec 27 21:08 src
drwxrwxr-x.  2 biocodee biocodee    6 Dec 27 21:08 tests

[biocodee@localhost Pjt]$ cat spec-file.txt 
# This file may be used to create an environment using:
# $ conda create --name <env> --file <this file>
# platform: linux-64
@EXPLICIT
https://repo.anaconda.com/pkgs/main/linux-64/_libgcc_mutex-0.1-main.conda
https://repo.anaconda.com/pkgs/main/linux-64/ca-certificates-2021.10.26-h06a4308_2.conda
https://repo.anaconda.com/pkgs/main/linux-64/ld_impl_linux-64-2.35.1-h7274673_9.conda
https://repo.anaconda.com/pkgs/main/linux-64/libstdcxx-ng-9.3.0-hd4cf53a_17.conda
https://repo.anaconda.com/pkgs/main/linux-64/libgomp-9.3.0-h5101ec6_17.conda
https://repo.anaconda.com/pkgs/main/linux-64/_openmp_mutex-4.5-1_gnu.tar.bz2
https://repo.anaconda.com/pkgs/main/linux-64/libgcc-ng-9.3.0-h5101ec6_17.conda
https://repo.anaconda.com/pkgs/main/linux-64/libffi-3.3-he6710b0_2.conda

#use the spec file to create an identical environment on the same machine or another machine
$ conda create --name myenv --file spec-file.txt

#use the spec file to install its listed packages into an existing environment
$ conda install --name myenv --file spec-file.txt 
sharing environment

quickly reproduce your environment, with all of its packages and versions, give them a copy of your environment.yml file

Exporting the environment.yml file
  1. activate the environment to export :
$ conda activate myenv
  1. export environment to a new file :
#files handles both environment's pip packages and conda packages
$ conda env export > environment.yml
restoring an environment

"roll back" to previous version

#list history of changes $ conda list --revisions#restore env to a previous version , REVNUM : revision number, or cmd `conda install --rev REVNUM`$ conda install --revision=REVNUM 
removing an environment
$ conda remove  --name Newenv --all #or$ conda env remove --name Newenv#vertify$ conda info --envs

reference :

[1] Managing environments.site

[2] The Definitive Guide to Conda Environments.site

目录
相关文章
|
4月前
|
存储 JavaScript 前端开发
.env.development是什么
.env.development是什么
|
Shell Linux C++
报错:CommandNotFoundError: Your shell has not been properly configured to use ‘conda activate‘. 问题解决
报错:CommandNotFoundError: Your shell has not been properly configured to use ‘conda activate‘. 问题解决
236 0
|
C++ iOS开发
报错解决:Could not build wheels for soxr, which is required to install pyproject.toml-based projects(可用)
链接如下:【金山文档】 1-Microsoft Visual C++ Build Tools。找了好久,才找到正确的解决方案,网上一大堆升级setuptools的方法只对少数人管用。注意,虽然我的这个报错内容有点长,但是我感觉和其它的。如果网页提示登录,可以不用登录,直接下载即可。然后打开镜像ios文件(双击即可)错误是一样的解决方案。文件,打开后安装即可。
2558 1
报错解决:Could not build wheels for soxr, which is required to install pyproject.toml-based projects(可用)
|
Shell
CommandNotFoundError: Your shell has not been properly configured to use ‘conda activate‘.简单解决方案
CommandNotFoundError: Your shell has not been properly configured to use ‘conda activate‘.简单解决方案
1739 0
CommandNotFoundError: Your shell has not been properly configured to use ‘conda activate‘.简单解决方案
|
Shell
【已解决】CommandNotFoundError: Your shell has not been properly configured to use ‘conda activate‘.
【已解决】CommandNotFoundError: Your shell has not been properly configured to use ‘conda activate‘.
338 0
How applications are staged in SAP Cloud Platform CloudFoundry environment
How applications are staged in SAP Cloud Platform CloudFoundry environment
103 0
How applications are staged in SAP Cloud Platform CloudFoundry environment
|
JavaScript 前端开发
|
JavaScript 前端开发