conda环境管理

zhangzhijun 88次浏览 0个评论

修改conda默认env路径

默认情况下,conda创建的env路径如下:

操作系统

安装文件类型

默认路径

WindowsGraphical installer (.exe)

C:\Users\<USERNAME>\anaconda3\envs\

C:\Users\<USERNAME>\miniconda3\envs\

macOSGraphical installer (.pkg)

/opt/anaconda3/envs/

/opt/miniconda3/envs/

macOSCommand line installer (.sh)

/anaconda3/envs/

/miniconda3/envs/

LinuxCommand line installer (.sh)

/anaconda3/envs/

/miniconda3/envs/

创建env时可通过--prefix命令来指定环境路径,或者通过修改.condarc修改环境路径

channels:
 - defaults
default_channels:
 - https://repo.anaconda.com/pkgs/main
envs_dirs:
 - /Users/<USER>/conda-envs

创建env环境

方式1:通过命令创建

# Replace <ENV_NAME> with a name for your environment
# Replace each <PACKAGE> with the name of your desired packages
# Replace <VERSION> with your desired version (optional)
conda create --name <ENV_NAME> <PACKAGE>=<VERSION> <PACKAGE> <PACKAGE>

例如:

conda create --name myenv python=3.11 beautifulsoup4 docutils jinja2=3.1.4 wheel

方式2:通过yml文件创建

conda env create --file environment.yml

激活环境

# Replace <ENV_NAME> with the name of the environment you want to activate
conda activate <ENV_NAME>

例如:

Conda activate conda-beginner

切换环境

通过如下命令查询所有conda env

conda info --envs

通过下述命令切换conda env

# Replace <ENV_NAME> with the name of the environment you want to switch to
conda activate <ENV_NAME>

去激活环境

conda deactivate

版权申明:

本博客所有文章除特别声明外均采用 BY-NC-SA 4.0 许可协议。依据 BY-NC-SA 4.0 许可协议,转载请附上原文出处链接及本声明。

原文链接: https://zhangzhijun.life/condahuanjingguanli.html

Default Avatar

客官,说点什么吧!

此字段内容将保密,不会被其他人看见。