SoFunction
Updated on 2025-04-11

Summary of the creation and use of conda virtual environment in Python

0. Preface

conda is an open source package, environment manager, which can be used to create different virtual environments on the same machine, install different Python versions of software packages and their dependencies, and be able to switch between different virtual environments. Conda is often used by installing Anaconda/Miniconda. Generally, Miniconda is enough.

Install

Download Miniconda installation package

wget /miniconda/Miniconda3-latest-Linux-x86_64.sh

Install Miniconda

bash Miniconda3-latest-Linux-x86_64.sh
...
Please answer 'yes' or 'no':'
>>> yes
...
Miniconda3 will now be installed into this location:
/root/miniconda3

  - Press ENTER to confirm the location
  - Press CTRL-C to abort the installation
  - Or specify a different location below

[/root/miniconda3] >>> 
...
You can undo this by running `conda init --reverse $SHELL`? [yes|no]
[no] >>> yes

Configure domestic mirror source

conda config --add channels /anaconda/pkgs/main/
conda config --add channels /anaconda/pkgs/free/
conda config --add channels /anaconda/pkgs/r
conda config --add channels /anaconda/pkgs/msys2
conda config --set show_channel_urls yes

At this point, the installation is complete.

Basic local operations

Get the version number

conda --version or conda -V

Check for updates to the current conda

conda update conda

Check which virtual environments currently exist

conda env list or conda info -e or conda info --envs

View/install/update/delete packages

conda list:
conda search package_name
conda install package_name
conda install package_name=1.5.0
conda update package_name
conda remove package_name

3. Create a conda virtual environment

Create an environment named your_env_name

conda create --name your_env_name

Create an environment that formulates a python version

conda create --name your_env_name python=3.12

Create an environment that contains certain packages

conda create --name your_env_name numpy scipy

Create an environment containing certain packages under the specified python version

conda create --name your_env_name python=3.12 numpy scipy

4. Activate the conda virtual environment

Linux

 conda activate your_env_name

Windows

activate your_env_name

5. Exit the conda virtual environment

Linux

conda deactivate

Windows

deactivate env_name

6. Delete the conda virtual environment

conda remove -n your_env_name --all
conda remove --name your_env_name --all

7.Clone the conda virtual environment

conda create --name new_env_name --clone old_env_name

This is the article about the creation and use of conda virtual environment in Python. For more related content on creating Python conda virtual environment, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!