Simple operation of Anaconda virtual environment

Every time I use Anaconda, I forget the commands to create a virtual environment and open the environment, so today I will briefly record the common operations~

1. View the virtual environment

Open the command line through Anaconda Prompt to view the existing virtual environment

conda env list

2. Create a virtual environment

1. I use Anaconda because of its virtual environment. If you need different python versions to run code or run models, you will use different virtual environments. The creation command is as follows:

conda create -n yourname python==3.7

Among them, -n means -name. What needs to be modified is ①yourname, here it is changed to the name of the virtual environment you set; ②python version, here is 3.7, changed to the required version.

2. After the environment is created, run the command to enter the environment:

activate yourname

3. Exit the environment command:

deactivate yourname

3. Operation of virtual environment library

1. Check what libraries are in the environment:

conda list

Similar to the above one, view the virtual environment , but there is no intermediate env (environment).

2. If you need to add the library yourself, generally use pip or conda:

pip install 库
conda install 库

If you need to specify the version of the library, just modify "Library == Version" in the above code.

If you are adding the library from the requirements.txt file, use the command:

pip install -r requirements.txt

The premise is that the command line is set to the path where the file is located, and the specified path is set:

cd 指定路径

Tips: If the current path and the specified path are not in the same disk, for example, one is on the C drive and the other is on the D drive, you also need to enter the following command:

D:

3. If you need to delete the library, use pip or conda, and change "install" to "uninstall":

pip uninstall 库
conda uninstall 库

4. Delete the virtual environment

Without further ado, look at the following commands:

conda remove -n yourname  --all

Guess you like

Origin blog.csdn.net/fortune_mz/article/details/132418432