How to create a virtual environment in Anaconda on Linux?

To create a virtual environment in Linux using Anaconda, you can follow these steps:

  1. Open the terminal and activate the Anaconda environment. Enter the following command:
source ~/anaconda3/bin/activate
  1. Create a new virtual environment using the following command format:
conda create --name <虚拟环境名> <要安装的软件包>

To create a virtual environment named myenv and install Python 3.7, you can use the following command:

conda create --name myenv python=3.7
  1. Activate the virtual environment. The command format is:
conda activate <虚拟环境名>

For example, to activate a virtual environment named myenv, you can enter the following command:

conda activate myenv
  1. Install other software packages in the virtual environment. You can use the conda or pip command to install the necessary packages. For example, to install numpy in the myenv environment, you can enter the following command:
conda install numpy

Alternatively:

pip install numpy
  1. Exit the virtual environment by entering the following command:
conda deactivate

By following the steps above, you can create a virtual environment in Linux using Anaconda and install and manage software packages within the virtual environment.

bannerAds