conda virtual environment: how to use pip or conda to install and manage packages

This article will introduce how to use the cmd command window or anaconda promt to use the pip command or conda command to install and manage the libraries or packages required for Python.

 

Table of contents

A cmd command line window to manage the conda virtual environment

1 Use the win+R keys to enter cmd to open the command line window and go to the scripts directory of the corresponding virtual environment:

2 Method 1: Use pip to install the python library, enter the following code, package-name is the name of the corresponding library or package. 

3 Method 2: Use the conda tool to install the python library

2 anaconda promt installs python package


A cmd command line window to manage the conda virtual environment

  • First you need to find the directory path of the virtual environment. Mine is installed in the following directory:

 

         Each folder here represents an independent virtual environment (you name the virtual environment you created in anaconda). The following is an example of installing the corresponding package in a virtual environment called torch3.

  • The installation package is in the scripts directory:

 

 

1 Use the win+R keys to enter cmd to open the command line window and go to the scripts directory of the corresponding virtual environment:

 

2 Method 1: Use pip to install the python library, enter the following code, package-name is the name of the corresponding library or package. 

pip install package-name

 

3 Method 2: Use the conda tool to install the python library

        Both pip and conda are package installation management tools. Beginners do not need to be too careful about the difference between the two.

        The download address of conda is foreign by default, so it will be slower to download directly using the conda command. It is best to add some domestic mirror sources, and the speed of downloading the package will be much faster. To add, enter the following code on the command line.

#添加清华镜像源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/

       Use conda config --show channels to see whether the mirror address is added successfully.

        Enter the following code on the command line to install the corresponding package

conda install -n venv packagename
#或者是conda install packagename -n venv
# 如果不用-n指定环境名称,则被安装在当前激活环境
# 也可以通过-c指定通过某个channel安装

2 anaconda promt installs python package

1 First open prompt in the start interface

 2 Enter the corresponding virtual environment. The venv below is the name of the virtual environment you created yourself.

 

#• 激活虚拟环境,venv是你python虚拟环境名字
#on windows
activate venv
#on linux
source activate venv

 

 

 3 Install packages

# 安装package
conda install -n venvname pacakge
# 如果不用-n指定环境名称,则被安装在当前激活环境
# 也可以通过-c指定通过某个channel安装
也可以使用pip install 

Guess you like

Origin blog.csdn.net/weixin_51286347/article/details/128632701
Recommended