首页文章conda环境管理

conda环境管理

计算机技术 · python 程序开发2025-06-290次浏览0 个评论

修改conda默认env路径

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

操作系统安装文件类型默认路径
WindowsGraphical installer (.exe)C:\Users\\anaconda3\envs\C:\Users\\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修改环境路径

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

创建env环境

方式1:通过命令创建

text
# 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>

例如:

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

方式2:通过yml文件创建

text
conda env create --file environment.yml

激活环境

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

例如:

text
Conda activate conda-beginner

切换环境

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

text
conda info --envs

通过下述命令切换conda env

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

去激活环境

text
conda deactivate

评论

0

评论加载中…

发表评论

0/2000