首页 > 其他分享 >FAQ 关于pip你应该知道的一些技巧

FAQ 关于pip你应该知道的一些技巧

时间:2023-03-29 19:11:32浏览次数:63  
标签:技巧 -- pypi FAQ selenium install pip 安装

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 uninstall -r xxx.txt 来批量卸载

- 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]]

标签:技巧,--,pypi,FAQ,selenium,install,pip,安装
From: https://www.cnblogs.com/wuxianfeng023/p/16590598.html

相关文章

  • IDEA使用技巧和注册教程
    ​编辑切换为居中添加图片注释,不超过140字(可选)IntelliJIDEA是一款流行的Java集成开发环境(IDE),它为开发者提供了许多有用的功能和工具来提高他们......
  • dnslog小技巧
    大自然的搬运工转载自https://www.cnblogs.com/sstfy/p/10351807.htmldnslog小技巧 一、dnslog利用场景主要针对无回显的情况。Sql-BlindRCESSRFRFI(RemoteFile......
  • 【电脑操作技巧】重装系统之后的常用数据恢复方式和基础环境搭建
    这段时间我经历了人生中第一次(被迫)重装系统,有些数据的恢复花了好久才探索出来,因此,我想总结一下这几天的痛苦经历,重装系统或者购入新机的朋友可以看看。目录0.桌面恢复1.......
  • idea重构小技巧3,去掉临时变量
    idea重构小技巧2,去掉临时变量临时变量作为参数传递,很难阅读,提升了代码的阅读难度StringgroupId=context.getProcessModel().getOriginalMqMsg().getAlarmRule().getR......
  • mapbox-gl实战教程:加载各种底图技巧
    在地图开发中,加载底图是一个最基本的操作,使用在线开放底图、自己发布的底图、或是客户提供的给底图服务,都存在一定的规律,掌握规律就能顺利的进行底图加载,本文通过以下四个方......
  • PrimeFaces布局技巧
    PrimeFaces布局技巧作者:chszs布局组件Layout是一个高度可定制的边框布局模型,它可以很轻松地创建复杂的网页布局,即使不懂Web设计。一、布局组件Layout的属性布局组件Layout的......
  • Openfire使用上的一些技巧
    Openfire使用上的一些技巧作者:chszs1、把Openfire安装为系统服务对于RedHat、CentOS、Fedora之类的系统,可以采用RPM包安装Openfire,安装后自然有了Openfire服务。此时可以通......
  • API开发的版本控制技巧
    《API开发的版本控制技巧》作者:chszs在设计和构建API时,API的版本控制是非常重要的。必须确保新API对于现有的API不会造成破坏。首先,也是最重要的,可以把版本号放入API的URL中......
  • pip 安装问题
    Fatalerrorinlauncher:Unabletocreateprocessusing'"'running python-mpipinstall--upgradepip incmd ......
  • idea重构小技巧1,选中代码自动提取出来方法
    1.选中抽取方法选中代码右键->refactor->extractmethod生成新的方法,并放在当前同类下2.重新命名新抽取出来的方法为rewriteAlarmObject......