修改conda默认env路径
默认情况下,conda创建的env路径如下:
操作系统 | 安装文件类型 | 默认路径 |
Windows | Graphical installer (.exe) | C:\Users\<USERNAME>\anaconda3\envs\ C:\Users\<USERNAME>\miniconda3\envs\ |
macOS | Graphical installer (.pkg) | /opt/anaconda3/envs/ /opt/miniconda3/envs/ |
macOS | Command line installer (.sh) | /anaconda3/envs/ /miniconda3/envs/ |
Linux | Command 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