pip简介

  • pip是安装了python之后的一个应用程序,包管理程序,有点类似于yum、npm、apt等工具

  • 物理位置一般是python.exe所在目录下的scripts下

    • 以我为例,我Python安装在D:\Python39\下,那么pip就在D:\Python39\Scripts

    • 而这个工具所在的目录应该也在你系统的PATH中,否则你敲pip也无法调用它

    • pip.exe(windows物理文件名),别名还有pip3.exe和pip3.9.exe

  • python的包管理程序其实也有不少,比如PDM等

pip命令行

  • 命令行帮助(你可以跳过,仅作为参考即可)

 C:\Users\songqin008>pip --help
 ​
 Usage:
  pip <command> [options]
 ​
 Commands:
  install                     Install packages.
  download                   Download packages.
  uninstall                   Uninstall packages.
  freeze                     Output installed packages in requirements format.
  inspect                     Inspect the python environment.
  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.
  cache                       Inspect and manage pip's wheel cache.
  index                       Inspect information available from package indexes.
  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.
   --debug                     Let unhandled exceptions propagate outside the main subroutine, instead of logging them
                              to stderr.
   --isolated                 Run pip in an isolated mode, ignoring environment variables and user configuration.
   --require-virtualenv       Allow pip to only run in a virtual environment; exit with an error otherwise.
   -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.
   --no-input                 Disable prompting for input.
   --proxy <proxy>             Specify a proxy in the form scheme://[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 or host:port pair as trusted, even though it does not have valid or any
                              HTTPS.
   --cert <path>               Path to PEM-encoded CA certificate bundle. If provided, overrides the default. See 'SSL
                              Certificate Verification' in pip documentation for more information.
   --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.
   --no-python-version-warning
                              Silence deprecation warnings for upcoming unsupported Pythons.
   --use-feature <feature>     Enable new functionality, that may be backward incompatible.
   --use-deprecated <feature> Enable deprecated functionality, that will be removed in the future.

pip install 安装包

  • 这应该是用的比较多的一条命令

  • 典型的用法主要是

 pip  install   selenium  #又称软件包名
 ​
 pip install   selenium -i 安装源  # 手工临时指定安装源
 ​
 pip install    selenium==4.4.0  # 安装指定版本的软件包
  • 典型的安装源

地址
清华 https://pypi.tuna.tsinghua.edu.cn/simple/
豆瓣 http://pypi.doubanio.com/simple/
腾讯 https://mirrors.cloud.tencent.com/pypi/simple/
阿里云 https://mirrors.aliyun.com/pypi/simple/
   

pip list 列出当前解释器下的库

 C:\Users\songqin008>pip list
 Package               Version
 --------------------- -----------
 adbutils              0.13.1
 aiohttp               3.8.1
  • windows下可以通过findstr来过滤,linux下可以通过grep来过滤

pip show 查看某个库的信息

 C:\Users\songqin008>pip show selenium
 Name: selenium
 Version: 4.3.0
 Summary:
 Home-page: https://www.selenium.dev
 Author:
 Author-email:
 License: Apache 2.0
 Location: d:\python39\lib\site-packages
 Requires: trio, trio-websocket, urllib3
 Required-by: Appium-Python-Client, squitool, webdriver-helper
  • 关注

    • 版本:version

    • 依赖:requires

    • 被依赖:required-by

pip config 配置默认仓库

  • 这是一条容易被忽略的命令

  • 其实我们只需执行一次,后续就无需手工-i指定安装源了

 pip config set global.index-url http://pypi.tuna.tsinghua.edu.cn/simple
 ​
 pip config set global.trusted-host pypi.tuna.tsinghua.edu.cn/simple
  • 设置完成其实是在你本机生成一个文件(一般是家目录下的.pip隐藏目录下),pip.ini(win)或pip.conf(linux)

  • 内容大致如下

 [global]
 ​
 index-url = http://pypi.tuna.tsinghua.edu.cn/simple
 ​
 trusted-host = pypi.tuna.tsinghua.edu.cn
 ​
  • 换言之,你也可以自己手工写入如上内容

pip freeze 导出包信息

  • 导出当前解释器下的所有库,常用来移植

  • 命令行执行

 C:\Users\songqin008>pip freeze >requirements.txt
  • 文件内容大致如下

 adbutils==0.13.1
 aiohttp==3.8.1
 aiosignal==1.2.0
 akshare==1.4.17
 allure-pytest==2.9.45
 allure-python-commons==2.9.45
 anyio==3.5.0
 apkutils2==1.0.0
 Appium-Python-Client==2.6.0
 argon2-cffi==21.3.0
 argon2-cffi-bindings==21.2.0
  • 可以通过pip install -r requirements.txt来批量安装这些库

pip 典型问题

安装超时的处理

  • 多数是因为网络问题

  • 往往会提示你升级pip的版本

python -m pip install --upgrade pip
  • 也有可能是你没配置本地安装源,直接用的pypi(出国了),那你可以使用pip config来配置下。或者用pip install -i 来指定安装源。

  • 有的时候选择了安装源也无法安装,那可以从pypi下载源文件,解压后通过以下命令来安装

python setup.py install   # 安装
  • 除了setup.py还有whl文件也可以安装

pip install xxxx.whl

安装成功但没看到

  • 注意pip list前面我说的功能是列出当前解释器下的包

  • 如果你有多个环境那么你只会选择当前的

  • 以我本机为例,我就装了多个python环境,那么你pip list默认列出的就是第一个解释器(39)下的库。

C:\Users\songqin008>where pip
D:\Python39\Scripts\pip.exe
D:\Python37\Scripts\pip.exe
D:\anaconda3\Scripts\pip.exe
C:\Python310\Scripts\pip.exe
  • 看下面2个命令的输出,库是不一样的。

C:\Users\songqin008>pip3.7 list|findstr selenium
selenium 3.141.0 C:\Users\songqin008>pip3.9 list|findstr selenium
selenium 4.3.0
  • 所以大家在安装的时候务必要注意,如果你有多解释器(有的有虚拟环境),那么你用cmd的时候一定要注意是否要切换。

  • 初学者可以用pycharm这样的图形化IDE来安装,也是比较稳妥的。 ![[Pasted image 20220816091115.png]]

FAQ 关于pip你应该知道的一些技巧的更多相关文章

  1. 关于 pip 的 15 个使用小技巧

    认识pip 众所周知,pip可以对python的第三方库进行安装.更新.卸载等操作,十分方便. pip的全称:package installer for python,也就是Python包管理工具. ...

  2. 高手问答精选:Go 语言 —— 云计算时代的 C 语言(类似于一个FAQ)

    Go 语言被称为云计算时代的 C 语言,它在软件开发效率和运行效率之间做出了绝佳的权衡.这使得它既适应于互联网应用的极速开发,又能在高并发.高性能的开发场景中如鱼得水.正因如此,许多互联网公司,尤其是 ...

  3. AI框架类FAQ

    AI框架类FAQ 数据处理 问题:如何在训练过程中高效读取数量很大的数据集? 答复:当训练时使用的数据集数据量较大或者预处理逻辑复杂时,如果串行地进行数据读取,数据读取往往会成为训练效率的瓶颈.这种情 ...

  4. 2017Windows下安装pip

    -------------------------------------------- 下载地址:  https://pypi.python.org/pypi/pip#downloads 下载颜色那 ...

  5. 安装pip

    1. 安装pip. 我们同样需要在Python的官网上去下载,下载地址是: https://pypi.python.org/pypi/pip#downloads 2. 解压. 解压pip-9.0.1. ...

  6. Windows下Python中pip安装Pillow报错总结(转载)

    遇到的俩种错误1.ValueError: zlib is required unless explicitly disabled using --disable-zlib, aborting 问题原因 ...

  7. CentOS7下安装Python的pip

    root用户使用yum install -y python-pip 时会报如下错误: No package python-pip available Error:Nothing to do 解决方法如 ...

  8. django 第三天 有关pip使用

    软件应用开发的经典模型有这样几个环境:开发环境(development).集成环境(integration).测试环境(testing).QA验证,模拟环境(staging).生产环境(product ...

  9. pip安装指定版本的package

    起因 最近到一个项目组,用了一套高大上的运维工具来搭建开发环境. 有vagrant控制VirtualBox启动虚拟机.有ansible来运行playbook初始化环境. 然后遇到了一个坑,项目现有的p ...

  10. pip安装使用详解(转)

    pip类似RedHat里面的yum,安装Python包非常方便.本节详细介绍pip的安装.以及使用方法. 1.pip下载安装 1.1 pip下载   1 # wget "https://py ...

随机推荐

  1. 成熟企业级开源监控解决方案Zabbix6.2关键功能实战-下

    @ 目录 实战 Zabbix server源码安装使用示例 部署 配置 Zabbix agent2使用示例 部署 配置 Zabbix proxy使用示例 部署 配置 自定义监控使用示例 触发器使用示例 ...

  2. 自学 TypeScript 第三天 使用webpack打包 TS 代码

    前言: 大家好啊,昨天介绍了 TS 编译器的配置,但在我们实际开发当中直接使用 TS 编译器去编译代码的情况会有,但没有很多,因为我们在开发大型项目的时候,一般我们都会用到打包工具,也不可能脱离打包工 ...

  3. vue 3.0 常用api 的简介

    vue3.0 生命周期 写法一 和vue2.x 一致 区别在于(beforeUnmount.unmount)名称不一样 写法二 在setup 中使用, 需要引用 如: import { onBefor ...

  4. Python模块大全之《 os模块》

    ️前言: os 模块提供了非常丰富的方法用来处理文件和目录.是Python基础必备的,所以我用了6000字详细讲述了绝大部分os模块提供的方法,方法如下 方法一.os.makedirs()和os.re ...

  5. 简单的sql注入3

    仍然 1 1' 1" 发现1'报错了.....我觉得作者对'情有独钟 再试试 1# 1'# 1"# 发现都可以正常登录 试试1' and '1'='1和1' and '1'='2发 ...

  6. python基础语法/简单数据类型/常量与变量

    今日内容概要 PEP-8规范/python基础语法 变量与常量定义 基本数据类型(整形int,字符串str,浮点型float,字典dict,列表list) 到此我们前期的配置已经可以满足我们正常编写代 ...

  7. Vue3“直接”修改props

    父组件 import { reactive } from 'vue'; //对话框数据 const show = reactive({ isshow: false, }); //打开对话框 const ...

  8. MathNet用到的一些功能

    1.计算一元线性函数 Tuple<double, double> myLineTuple = MathNet.Numerics.Fit.Line(myXArray, myYArray); ...

  9. Day30.1:Math的常用方法

    Math 1.1 Math概述 Math类在Java.lang包下,不需要导包 public final class Math extends Object Math含有基本的数字运算方法,没有构造器 ...

  10. ChatGPT 可以联网了!浏览器插件下载

    Twitter 用户 An Qu 开发了一款新的 Chrome 插件帮助 ChatGPT 上网,安装插件以后 ChatGPT 就可以联!网!了! 简单来说开启插件后,他可以从网上搜索信息,并且根据用户 ...