Create and remove virtual environment by Anaconda

2024-02-16
2017-01-05

You can create virtual environment and execute Python program in it if you use Anaconda. It makes it easy to change Python version and manage packages.

Create environment

With name

termimnal

$ conda create -n myenv

Create the virtual environment as "myenv". In this case, install Python of the latest version.

Create the virtual environment as "myenv". This will install the latest version of Python.

Specify Python version

terminal

$ conda create -n myenv python=3.7

Install Python 3.6 with the option Python=3.6.

Specify the packages

If you specify the packages, you can install these when creating the environment.

terminal

$ conda create -n myenv matplotlib

You can specify the version of the package, such as matplotlib=3.0.0.

terminal

$ conda create -n myenv python=3.7 matplotlib=3.0.0

Remove the environment

terminal

$ conda remove -n myenv --all

Show the list of the environment

terminal

$ conda-env list

The conda command also displays the list.

terminal

$ conda info --envs

Switch the environment

Activate

terminal

$ conda activate myenv

Deactivate

terminal

(myenv) $ conda deactivate