百木园-与人分享,
就是让自己快乐。

pip常见命令

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。

本文来自博客园,作者:ivanlee717,转载请注明原文链接:https://www.cnblogs.com/ivanlee717/p/16265856.html


来源:https://www.cnblogs.com/ivanlee717/p/16265856.html
本站部分图文来源于网络,如有侵权请联系删除。

未经允许不得转载:百木园 » pip常见命令

相关推荐

  • 暂无文章