`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

目录
相关文章
|
JavaScript 前端开发
|
开发工具 Python Windows
QA Best Practices in Rapid Iterative Development
Introduction and Background Although rapid iterative development has become a popular approach to software development, many development teams are u.
1672 0
|
Python
Installing the required software
Installing Python on Mac OSX Installing virtualenv$ pip3 install virturalenv -- 安装虚拟环境 $ virtualenv ENV -- 创建自己的虚拟环境,会创建如图下的目录结构 virtualenv-15.
1016 0
|
SQL 关系型数据库 数据库