pip常见命令

yizhihongxing

linux常用的一些命令笔记___pip3

[root@localhost ~]# pip3 --help

Usage:   
  pip3 <command> [options]

Commands:
  install                     Install packages.
  download                    Download packages.
  uninstall                   Uninstall packages.
  freeze                      Output installed packages in requirements format.
  list                        List installed packages.
  show                        Show information about installed packages.
  check                       Verify installed packages have compatible dependencies.
  config                      Manage local and global configuration.
  search                      Search PyPI for packages.
  wheel                       Build wheels from your requirements.
  hash                        Compute hashes of package archives.
  completion                  A helper command used for command completion.
  debug                       Show information useful for debugging.
  help                        Show help for commands.

General Options:
  -h, --help                  Show help.
  --isolated                  Run pip in an isolated mode, ignoring environment variables and user configuration.
  -v, --verbose               Give more output. Option is additive, and can be used up to 3 times.
  -V, --version               Show version and exit.
  -q, --quiet                 Give less output. Option is additive, and can be used up to 3 times (corresponding to WARNING, ERROR, and CRITICAL logging levels).
  --log <path>                Path to a verbose appending log.
  --proxy <proxy>             Specify a proxy in the form [user:passwd@]proxy.server:port.
  --retries <retries>         Maximum number of retries each connection should attempt (default 5 times).
  --timeout <sec>             Set the socket timeout (default 15 seconds).
  --exists-action <action>    Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort.
  --trusted-host <hostname>   Mark this host as trusted, even though it does not have valid or any HTTPS.
  --cert <path>               Path to alternate CA bundle.
  --client-cert <path>        Path to SSL client certificate, a single file containing the private key and the certificate in PEM format.
  --cache-dir <dir>           Store the cache data in <dir>.
  --no-cache-dir              Disable the cache.
  --disable-pip-version-check
                              Don't periodically check PyPI to determine whether a new version of pip is available for download. Implied with --no-index.
  --no-color                  Suppress colored output

安装 & 移除

  • 安装指定包的最新版
    pip3 install pkg_name

  • 安装制定包的指定版本
    pip3 install pkg_name==version

  • 移除指定包
    pip3 uninstall pkg_name

  • 在 PyPI 上模糊查找相关包
    pip3 search pkg_name

查看相关

  • pip install/download

    install是联网安装,而download是本地离线下载

    pip download pkg_name -d download_path 
    
  • 查看已经安装的包

    pip3 list

    [root@localhost ~] pip3 list
    Package            Version  
    ------------------ ---------
    aiohttp            3.7.4    
    amqp               5.0.5    
    async-timeout      3.0.1    
    attrs              20.3.0   
    
  • 查看指定包的相关信息

    pip3 show pkg_name

    [root@localhost ~] pip3 show zipp
    Name: zipp
    Version: 3.4.0
    Summary: Backport of pathlib-compatible object wrapper for zip files
    Home-page: https://github.com/jaraco/zipp
    Author: Jason R. Coombs
    Author-email: jaraco@jaraco.com
    License: UNKNOWN
    Location: /usr/local/python3/lib/python3.8/site-packages
    Requires: 
    Required-by: importlib-metadata, ratel
    

    Requires 和 Required-by 两个属性分别表示 zip 要依赖和被依赖的包情况;zipp 不需要任何依赖,而 zipp 被importlib-metadata和ratel依赖,所以删除之后会影响这两个的使用,最好对request 所有的依赖依次使用 pip show 运行一下查看具体依赖情况。

  • 输出所有在本地已安装的包

    pip3 freeze: 使用 pip freeze 会输出所有在本地已安装的包(但不包括 pipwheelsetuptools 等自带包),若需要输出内容与 pip list 一致,需使用 pip freeze -all

    [root@localhost ~] pip3 freeze all
    aiohttp==3.7.4
    amqp==5.0.5
    async-timeout==3.0.1
    attrs==20.3.0
    Automat==20.2.0
    beautifulsoup4==4.9.3
    

    pip3 freeze > requirements.txt: 当我们开发项目的时候会出现在不同环境下安装相同的模块的时为了避免我们通过联网下载所需模块,我们直接从之前python环境已经有的模块中直接拿来用。

    所以一般这个命令需要虚拟环境来维护当前的包版本,防止不同项目的不同版本包放在一起会造成混乱

    image-20220513100924869

  • 修改pip配置文件

    pip3 config

    国内源

    清华: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/
    
    • pip config set

      这个命令允许我们以name=value的形式配置某些项,比如设置镜像源:

      pip config set global.index-url https://mirrors.cloud.tencent.com/pypi/simple
      
    • pip config get

      这个命令允许我们查看某个配置项的值,比如查看镜像源配置:

      pip config get global.index-url
      
    • pip config edit

      这个命令允许我们用一个编辑器打开配置文件进行编辑,如果我们没有指定--editor选项,就会用VISUAL或者EDITOR环境变量的值作为编辑器,如下命令:

      pip config --editor=vi edit
      
    • pip config list

      这个命令以name=value的形式输出当前配置,假如我们已经执行了上面的pip config set命令,这时再执行 pip config list就会输出如下:

      global.index-url='https://mirrors.cloud.tencent.com/pypi/simple'
      
    • pip3 config debug

      这个命令列出各个配置文件位置及其内容

    • pip3 config unset

  • 检查需要的包的缺失匹配情况

    pip3 check

    [root@localhost ~]# pip3 check
    paramiko 2.10.3 requires bcrypt, which is not installed.
    paramiko 2.10.3 requires cryptography, which is not installed.
    pynacl 1.5.0 requires cffi, which is not installed.
    
  • pip3 --disable-pip-version-check install --no-index --find-links=

    第一个参数 --disable-pip-version-check 后面跟着的注释大意为:不要定期检查PyPI以确定是否有新版本的pip可供下载。暗示和--no-index联用

    意思就是一般在断网情况下的离线安装,都是直接从其他主机安装资源包,所以要取消更新

    其中 --no-index 代表忽视pip 忽视默认的依赖包索引。--find-links= 代表从你指定的目录寻下找离线包

  • pip download --platform anylinux_x86_64 --no-deps on -d pip_packages/ -r project/requirements.txt

    其中:--platform 指定平台信息, --no-deps:on 代表不安装依赖项。-d 后面指定依赖包下载目录。最后跟上requirement.txt。

本站文章如无特殊说明,均为本站原创,如若转载,请注明出处:pip常见命令 - Python技术站

(0)
上一篇 2023年4月2日 下午5:36
下一篇 2023年4月2日

相关文章

  • 数据分析之pandas的使用

    pandas 为什么学习pandas numpy已经可以帮助我们进行数据的处理了,那么学习pandas的目的是什么呢? numpy能够帮助我们处理的是数值型的数据,当然在数据分析中除了数值型的数据还有好多其他类型的数据(字符串,时间序列),那么pandas就可以帮我们很好的处理除了数值型的其他数据! 什么是pandas? 首先先来认识pandas中的两个常用…

    2023年4月2日
    00
  • Django_request学习

    Django_request (1)请求方式 这里使用一个接口测试软件postman 可以看到里面有非常多的发起请求的方式,最常用的就是GET和POST请求,但是这些方法无法在网页的url里显示 在学习request参数之前,django框架中首先接到浏览器发来的请求第一站是经过框架自带的wsgi.py文件 “”” WSGI config for djang…

    2023年4月2日
    00
  • pandas数据清洗

    数据清洗 数据清洗是对一些没有用的数据进行处理的过程。 很多数据集存在数据缺失、数据格式错误、错误数据或重复数据的情况,如果要对使数据分析更加准确,就需要对这些没有用的数据进行处理。 在这个教程中,我们将利用 Pandas包来进行数据清洗。 处理丢失数据 有两种丢失数据: None np.nan(NaN) 两种丢失数据的区别 为什么在数据分析中需要用到的是浮…

    2023年4月2日
    00
  • 爬虫学习1——request使用

    爬虫 什么是爬虫: – 通过编写程序,模拟浏览器上网,然后让其去互联网上抓取数据的过程。 爬虫究竟是合法还是违法的? 在法律中是不被禁止 具有违法风险 善意爬虫 恶意爬虫 爬虫带来的风险可以体现在如下2方面:- 爬虫干扰了被访问网站的正常运营- 爬虫抓取了收到法律保护的特定类型的数据或信息 如何在使用编写爬虫的过程中避免进入局子的厄运呢? – 时常的优化自己…

    2023年3月31日
    00
  • CSRF和token以及用django实现

    csrf CSRF(Cross-Site Request Forgery,跨站点伪造请求)是一种网络攻击方式,该攻击可以在受害者毫不知情的情况下以受害者名义伪造请求发送给受攻击站点,从而在未授权的情况下执行在权限保护之下的操作,具有很大的危害性。具体来讲,可以这样理解CSRF攻击:攻击者盗用了你的身份,以你的名义发送恶意请求,对服务器来说这个请求是完全合法的…

    2023年4月2日
    00
  • django_响应对象

    Django_响应对象 响应对象 响应对象有三种形式: HttpResponse() render() Redirect() (1) HttpResponse() django服务器接收到客户端发来的请求之后,会将提交上来的数据封装成一个HttpResponse对象传给视图函数。视图函数在处理完相关逻辑之后,也需要一个返回响应给浏览器。而这个响应方式,我们必…

    2023年4月2日
    00
  • django中间件以及自定义中间件

    middleware 中间件就是在目标和结果之间进行的额外处理过程,在Django中就是request和response之间进行的处理,相对来说实现起来比较简单,但是要注意它是对全局有效的,可以在全局范围内改变输入和输出结果,因此需要谨慎使用,否则不仅会造成难以定位的错误,而且可能会影响整体性能。 中间件有什么用 如果想要修改HttpRequest或者Htt…

    2023年4月2日
    00
  • django学习__1

    Django python网络编程回顾 之前我们介绍过web应用程序和http协议,简单了解过web开发的概念。Web应用程序的本质 接收并解析HTTP请求,获取具体的请求信息 处理本次HTTP请求,即完成本次请求的业务逻辑处理 构造并返回处理结果——HTTP响应 import socket server = socket.socket() server.b…

    Python开发 2023年4月2日
    00
合作推广
合作推广
分享本页
返回顶部