`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

目录
相关文章
|
数据采集 安全 API
安全工具的无限联动——真香系列来啦~
安全工具的无限联动——真香系列来啦~
1521 0
|
11月前
|
人工智能 弹性计算 调度
阿里云无影AgentBay是什么?AgentBay使用、积分计费规则及问题解答FAQ
阿里云无影AgentBay是面向AI Agent的云基础设施,提供浏览器、桌面、代码、移动端全覆盖的安全沙箱环境,支持SDK与MCP接入,助力开发者高效构建与运行智能体。新用户可0.01元领取100积分体验券,用于抵扣资源消耗。平台支持秒级弹性伸缩、千级并发调度,适用于金融分析、跨境电商、医疗诊断等多场景。采用基础权益包+订阅包+后付费模式,灵活计费。
923 1
|
Oracle 关系型数据库 数据库
docker下安装oracle11g(一次安装成功)
docker下安装oracle11g(一次安装成功)
1974 0
|
Shell 测试技术 API
Claude Code 官方内部团队最佳实践!
Immerse,独立开发者、内容创作者、AGI实践者,分享编程、AI、开源等内容。关注公众号“沉浸式趣谈”及个人网站获取更新。欢迎点赞、评论、转发支持!本文介绍Claude Code——智能编程命令行工具及其使用技巧。
8421 0
|
安全 Java Shell
Java模块化编程(JPMS)简介与实践
本文全面解析Java 9模块化系统(JPMS),帮助开发者解决JAR地狱、类路径冲突等常见问题,提升代码的封装性、性能与可维护性。内容涵盖模块化核心概念、module-info语法、模块声明、实战迁移、多模块项目构建、高级特性及最佳实践,同时提供常见问题和面试高频题解析,助你掌握Java模块化编程精髓,打造更健壮的应用。
|
机器学习/深度学习 人工智能 搜索推荐
拔俗戒毒所青少年AI心理疏导系统:用技术叩开“心门”的科学路径
针对青少年戒毒心理疏导难题,我们研发AI心理陪伴系统,融合语音、微表情与生理信号多模态识别技术,精准捕捉情绪;通过大模型生成个性化干预策略,动态评估疏导效果,实现“数据驱动”的人机协同疏导新模式,助力迷途少年回归正轨。
653 0
|
机器学习/深度学习 计算机视觉
YOLOv11改进策略【注意力机制篇】| 2023 MCAttention 多尺度交叉轴注意力 获取多尺度特征和全局上下文信息
YOLOv11改进策略【注意力机制篇】| 2023 MCAttention 多尺度交叉轴注意力 获取多尺度特征和全局上下文信息
720 1
YOLOv11改进策略【注意力机制篇】| 2023 MCAttention 多尺度交叉轴注意力 获取多尺度特征和全局上下文信息
|
Web App开发 数据可视化 搜索推荐
2024年深受用户喜爱的桌面工作安排软件——6款工具精选
本文介绍了六款桌面工作安排软件:板栗看板、Trello、Any.do、TickTick、Asana 和 Monday.com。这些软件通过集成日历、任务管理和项目管理功能,帮助用户优化工作流程、提升个人和团队的生产力。每款软件都有其独特的优势,适合不同的工作场景和需求,如个人任务管理、团队协作、项目管理和创意设计等。选择合适的工具,可以显著提高工作效率和团队协作效果。
2037 1
2024年深受用户喜爱的桌面工作安排软件——6款工具精选
ERROR: No matching distribution found for gradio>=3.23
该博客文章提供了解决使用pip安装gradio版本3.23时出现的"No matching distribution found"错误的步骤,包括从官网下载相应的whl文件并手动安装。
ERROR: No matching distribution found for gradio>=3.23
|
C语言
【C语言篇】分支语句详解(超详细)
在 switch 语句中 case 语句和 default 语句是没有顺序要求的,只要顺序是满⾜实际需求的就可以。 不过我们通常是把 default ⼦句放在最后处理的。
1062 2