search
HomeBackend DevelopmentPython TutorialDetailed explanation of common pip commands in Python

The editor believes that most people who are familiar with Python must have heard of and used the pip tool, but their understanding of it may not be very thorough. Today I will introduce to you 10 A little tip on using pip, I believe it will be helpful for you to manage and use the standard library in Python in the future.

Installation

Of course, after Python 3.4 and Python 2.7.9, the installation package on the official website already comes with pip, and users can use it directly after installing Python. , if you use a virtual environment created by virtualenv or pyvenv, then pip is also installed by default.

If you need to install the pip package yourself, run the following command line in an environment where Python has been configured.

py -m ensurepip --upgrade

Another way is to download it from the official website ​​Download the get-pip.py script directly, and then run the python get-pip.py script directly

How to use

After installation, enter pip in the command line, Then press Enter, and the instructions shown in the picture below will appear:

Detailed explanation of common pip commands in Python

Upgrade

If you feel that your pip version is a bit low, think about it. To upgrade, enter the following command on the command line

pip install --upgrade pip

or

pip install -U pip

to install a certain version of the package

If you plan to use pip to install third-party packages , the following command line is used

pip install package-name

For example, we want to install a specified version of a third-party package, such as installing version 3.4.1 of matplotlib,

pip install matplotlib==3.4.1

Uninstall or update the package

If you plan to uninstall a certain package, the command line to enter is

pip uninstall package_name

and if you plan to update a certain package, the corresponding command line is

pip install --upgrade package_name# 或者是pip install -U package_name

View The information of a certain package can be viewed through the following command line.

pip show -f requests

output

Name: requests
Version: 2.24.0
Summary: Python HTTP for Humans.
Home-page: https://requests.readthedocs.io
Author: Kenneth Reitz
Author-email: me@kennethreitz.org
License: Apache 2.0
Location: c:userspc120pycharmprojectspythonproject1venvlibsite-packages
Requires: certifi, chardet, idna, urllib3
Required-by: etelemetry, gTTS, pandas-datareader, pandas-profiling, pyler, pywhatkit, pyxnat, streamlit, tushare, wikipedia, yfinance
Files:
requests-2.24.0.dist-infoDESCRIPTION.rst
requests-2.24.0.dist-infoINSTALLER
.......

View the package that needs to be upgraded

We need to check it Among these existing packages, which ones need to be upgraded, you can use the following command line to check,

pip list -o

output

PackageVersion Latest Type
---------- ------- ------ -----
docutils 0.15.20.18.1 wheel
PyYAML 5.4.1 6.0wheel
rsa4.7.2 4.8wheel
setuptools 56.0.062.1.0 wheel

Check compatibility issues

in When downloading and installing some standard libraries, you need to consider compatibility issues. The installation of some standard libraries may need to rely on other standard libraries, and there may be problems such as version conflicts. Let us first use the following command line to check whether there are conflicts. problem exists.

pip check package_name

Of course, if we do not specify which standard library it is, we will check whether there are version conflicts and other issues in all currently installed packages.

pip check

output

yfinance 0.1.70 has requirement requests>=2.26, but you have requests 2.24.0.
selenium 4.1.0 has requirement urllib3[secure]~=1.26, but you have urllib3 1.25.11.

Specify domestic sources to install

If we feel that the installation speed is a bit slow, we can specify domestic sources to install a certain package, such as

pip install -i https://pypi.douban.com/simple/ package_name

There are domestic sources

清华:https://pypi.tuna.tsinghua.edu.cn/simple
阿里云:http://mirrors.aliyun.com/pypi/simple/
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
华中理工大学:http://pypi.hustunique.com/
山东理工大学:http://pypi.sdutlinux.org/ 
豆瓣:http://pypi.douban.com/simple/

Download the package but not install it

If we want to download a package to the specified path, the command line is as follows

pip download package_name -d "某个路径"

For example,

pip download requests -d "."

downloads the requests module and other dependent modules in the current directory.

Batch installation of software packages

When we see other people's projects, we usually include a requirements.txt file, which contains some third-party libraries that need to be used in Python projects.

Detailed explanation of common pip commands in Python

To generate this kind of txt file, you need to do this

pip freeze > requirements.txt

And if we need to install third-party libraries in batches, enter the following in the command line This command

pip install -r requirements.txt


The above is the detailed content of Detailed explanation of common pip commands in Python. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:51CTO.COM. If there is any infringement, please contact admin@php.cn delete
详细讲解Python之Seaborn(数据可视化)详细讲解Python之Seaborn(数据可视化)Apr 21, 2022 pm 06:08 PM

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于Seaborn的相关问题,包括了数据可视化处理的散点图、折线图、条形图等等内容,下面一起来看一下,希望对大家有帮助。

详细了解Python进程池与进程锁详细了解Python进程池与进程锁May 10, 2022 pm 06:11 PM

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于进程池与进程锁的相关问题,包括进程池的创建模块,进程池函数等等内容,下面一起来看一下,希望对大家有帮助。

Python自动化实践之筛选简历Python自动化实践之筛选简历Jun 07, 2022 pm 06:59 PM

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于简历筛选的相关问题,包括了定义 ReadDoc 类用以读取 word 文件以及定义 search_word 函数用以筛选的相关内容,下面一起来看一下,希望对大家有帮助。

归纳总结Python标准库归纳总结Python标准库May 03, 2022 am 09:00 AM

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于标准库总结的相关问题,下面一起来看一下,希望对大家有帮助。

Python数据类型详解之字符串、数字Python数据类型详解之字符串、数字Apr 27, 2022 pm 07:27 PM

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于数据类型之字符串、数字的相关问题,下面一起来看一下,希望对大家有帮助。

分享10款高效的VSCode插件,总有一款能够惊艳到你!!分享10款高效的VSCode插件,总有一款能够惊艳到你!!Mar 09, 2021 am 10:15 AM

VS Code的确是一款非常热门、有强大用户基础的一款开发工具。本文给大家介绍一下10款高效、好用的插件,能够让原本单薄的VS Code如虎添翼,开发效率顿时提升到一个新的阶段。

详细介绍python的numpy模块详细介绍python的numpy模块May 19, 2022 am 11:43 AM

本篇文章给大家带来了关于Python的相关知识,其中主要介绍了关于numpy模块的相关问题,Numpy是Numerical Python extensions的缩写,字面意思是Python数值计算扩展,下面一起来看一下,希望对大家有帮助。

python中文是什么意思python中文是什么意思Jun 24, 2019 pm 02:22 PM

pythn的中文意思是巨蟒、蟒蛇。1989年圣诞节期间,Guido van Rossum在家闲的没事干,为了跟朋友庆祝圣诞节,决定发明一种全新的脚本语言。他很喜欢一个肥皂剧叫Monty Python,所以便把这门语言叫做python。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),