Summary of pip usage

about pip

As a package manager, pip can be very convenient to install, update, and uninstall python's third-party libraries.

upgrade pip

pip install --upgrade pip
pip install -U pip

The difference between pip and pip3

1. Pip is a package management tool for python. The versions of pip and pip3 are different, and they are both located in the Scripts\ directory.
2. If only Python2 is installed in the system, then only pip can be used.
3. If only Python3 is installed in the system, you can use either pip or pip3, the two are equivalent.
4. If both Python2 and Python3 are installed in the system, pip is used for Python2 by default, and pip3 is assigned for Python3.
5. Important: In the virtual environment, if there is only one python version, it can be considered that the pip and pip3 commands in the system are the same.

search module

pip-search

pip search has been disabled, you need to install the pip-search package

#Install

pip install pip-search

#use

pip_search requests

View installable versions

You can query the historical version of a certain library by entering pip index versions bert4keras, so that some functions cannot be used due to inconsistencies in the update of some libraries.
This method can only be used for newer versions of pip;

pip index versions [package_name]

If it is an older version, if pip does not have the subcommand index, you can use: pip install package_name==

pip install package_name==

install module

Install the default version

pip install package

Install the specified version

pip install package==version
#package: package name; version: version number

 Specify mirror source installation

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple  tensorflow

Install to specified location

Use the --target parameter during installation to install it into your own project. It should be installed in the venv\Lib\site-packages folder under the project file, and venv is a virtual environment. For example, the project is D:\FlaskPythonProject, and the library installation code is:

pip3 install flask --target=D:\FlaskPythonProject\venv\Lib\site-packages

The library can be installed to the specified location

pip3 install flask --target=D:\FlaskPythonProject\lib

Use sys.path.append to add the search directory in the code

import os,sys
os.chdir("./") # Set project path
sys.path.append("./lib")
import flask

source:

​​​​​​Python installation library common commands-pudn.com

Check

Show all packages and their versions

If the number of installed packages is not enough, you can directly use pip list and pip freeze to display all packages and their versions.

pip list

pip freeze

If you need to output all installed packages in the current environment, or generate a requirements file and install from that file to another environment. You can use pip freeze command.

 Generate Python environment migration requirements file

pip freeze > requirements.txt

Display package information

pip show not only displays the version of the installed package, but also its URL, introduction and other information.

pip show selenium

Check for package compatibility issues

To verify that installed packages have compatibility dependencies, you can use 
If you do not specify a package name, it will check all packages for compatibility.

pip check package-name

export

export requirements.txt

Export the current environment

Batch export a requirements.txt file containing all components in the environment

pip freeze > requirements.txt

export current project

If you only want to export the requirements.txt file required by the current project

#Under the linux system: enter the directory where the python script is located, and directly execute the following code
pipreqs ./


#Under the windows system: cmd command enters the directory where the script is located, and executes the following code
pipreqs ./ --encoding=utf-8


#If requirements.txt already exists, execute
pipreqs ./ --encoding=utf-8 --force

Source: Generate requirements.txt file - know almost 

Export the offline package to the specified folder

Download the package written in requests.txt from the network of the current environment, and download it to the pip_packages directory under the current directory. At this time, you will find that there are many dependencies and some whl files in it.

pip download  -r requirements.txt  -d  ./pip_packages    

import

Install online

The requirements.txt contains the third-party library
pip to batch install the component dependencies contained in the requirements.txt file

pip install -r requirements.txt

Install offline

--find-links specifies the storage address of the package file, and -r specifies the location of the txt file

pip install --no-index --find-links=d:\packages -r requirements.txt 

source

[python] Use conda or pip to export and install requirements.txt_All_In_gzx_cc's blog-CSDN blog_conda download requirements

renew

View all updatable modules

pip list --outdated


update a module

pip install --upgrade package

pip install -U package_name


Specify the update source to update the module 

pip install --upgrade -i https://pypi.tuna.tsinghua.edu.cn/simple package

update all modules

pip-review --local --interactive

source

https://www.csdn.net/tags/MtjaAg2sNDU2MjctYmxvZwO0O0OO0O0O.html

uninstall module

It is recommended to uninstall the previous version of the module before installing the required version of the module. If it is a module update, it does not need to be uninstalled

pip uninstall package

source:

https://www.toutiao.com/article/7138663832427250210/?log_from=5d974dde881a1_1665578570933

conda and pip acceleration

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
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/bioconda/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --set show_channel_urls yes 

pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
pip config set install.trusted-host mirrors.aliyun.com 

source:

Anaconda configures domestic mirror source + explanation of common configuration commands - Programmer Sought

 PIP mirror source configuration is easy to get_pip mirror source configuration_ttlan's blog-CSDN blog

Guess you like

Origin blog.csdn.net/csdncjh/article/details/127291113