Post

Conda Environment Settings如何用conda创建环境并配置环境变量

Conda Environment Settings如何用conda创建环境并配置环境变量

This article was written with the assistance of GitHub Copilot 本文采用GitHub Copilot辅助写作

Create a new environment

To create a new conda environment, use the following command:

1
conda create --name myenv

Replace myenv with the name you want for your environment. You can also specify the Python version:

1
conda create --name myenv python=3.8

Alternatively, you can create an environment at a specific path using the -p option:

1
conda create -p /path/to/myenv

Replace /path/to/myenv with your desired path. You can also specify the Python version:

1
conda create -p /path/to/myenv python=3.8

Set environment variables for a specific environment

To set environment variables for a specific conda environment, use the conda env config vars set command. For example:

1
conda env config vars set MY_VAR=value

Replace MY_VAR and value with your desired variable name and value.

Activate the environment to apply the changes:

1
conda activate myenv

To view the environment variables set for the active environment, use:

1
conda env config vars list

To unset an environment variable, use:

1
conda env config vars unset MY_VAR

Replace MY_VAR with the name of the variable you want to unset.

For more details, refer to the official conda documentation.

Example: Setting PYTHONPATH

To set the PYTHONPATH environment variable for a specific conda environment, use the following command:

1
conda env config vars set PYTHONPATH=/path/to/your/modules

Replace /path/to/your/modules with the path you want to add to PYTHONPATH.

Activate the environment to apply the changes:

1
conda activate myenv

To verify that PYTHONPATH has been set, you can list the environment variables:

1
conda env config vars list

Delete an environment

To delete a conda environment, use the conda remove command with the --name option. For example:

1
conda remove --name myenv --all

Replace myenv with the name of the environment you want to delete. The --all flag ensures that all packages in the environment are removed.

Alternatively, if you created the environment at a specific path, use the -p option:

1
conda remove -p /path/to/myenv --all

Replace /path/to/myenv with the path to the environment you want to delete.

For more details, refer to the official conda documentation.

This post is licensed under CC BY 4.0 by the author.

Trending Tags