当前位置: 首页 > news >正文

python pip详解1

一、简介

pip是python的一个软件包管理工具,同yum,apt作用一致,pip有两种使用方式:pip模块和pip命令,示例如下:

python -m pip install package
pip install package

二、命令行详解

python -m pip --help

C:\Users\love1>python -m pip --helpUsage:C:\Users\love1\AppData\Local\Programs\Python\Python311\python.exe -m 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.

1、安装pip

get-pip

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py   # 下载安装脚本
python get-pip.py    # 运行安装脚本

注意: 用哪个版本的 Python 运行安装脚本,pip 就被关联到哪个版本,如果是 Python3 则执行以下命令:

python3 get-pip.py    # 运行安装脚本

ensurepip

python -m ensurepip
python -m ensurepip --upgrade  # 安装最新版本的

详见安装链接

2、配置

pip通过三种方式来配置相关配置项

  • command line options 命令行选项
  • environment variables 环境变量
  • configuration files 配置文件

配置文件的格式是INI格式

environment variables 环境变量
pip可以通过环境变量来替代命令行选项,格式为PIP_<UPPER_LONG_NAME>,用(_)代替(-),示例如下:

PIP_TIMEOUT=60--timeout=60
PIP_FIND_LINKS="http://mirror1.example.com http://mirror2.example.com"--find-links=http://mirror1.example.com --find-links=http://mirror2.example.com
PIP_VERBOSE=3 同 pip install -vvv

configuration files
有三种层级的配置文件可以用

  • global 系统范围的配置文件,所有用户共享
    该配置文件存放于XDG_CONFIG_DIRS环境变量所代表的目录下,常见目录为/etc/xdg/pip/pip.conf或者/etc/pip.conf
  • user 用户范围的配置文件
    XDG_CONFIG_HOME环境变量所代表的配置文件,常见目录为$HOME/.config/pip/pip.conf或者$HOME/.pip/pip.conf
  • site 环境范围内的配置文件
    $VIRTUAL_ENV/pip.conf

PIP_CONFIG_FILE环境变量也可以指定配置文件路径,但是如果该值被设置为os.devnull,则将禁用所有的配置文件

加载顺序 loading order

  • Global
  • User
  • Site
  • PIP_CONFIG_FILE, if given
    pip会按照上述顺序加载配置文件,但是后加载的配置文件会覆盖前面加载的配置文件,如果配置文件中有相同项配置的话。

在配置文件中按照命令来区分
示例如下

[global]
find-links =http://download.example.com
timeout = 60[freeze]
timeout = 10[install]
find-links =http://mirror1.example.comhttp://mirror2.example.comtrusted-host =mirror1.example.commirror2.example.com

上述按照命令区分的含义是,当执行pip freeze的时候,timeout 的值是10而不是60;当执行pip install 的时候timeout 的值是60,但是find-links的值是 http://mirror1.example.com http://mirror2.example.com

生效优先级
命令行选项>环境变量>PIP_CONFIG_FILE配置文件>site配置文件>user 配置文件>global配置文件
在配置文件中 [<command>] host = bar > [<global>] host

–host=foo 会覆盖 PIP_HOST=foo
PIP_HOST=foo 会覆盖配置文件中的[global] host = foo

详见配置文件

http://www.lryc.cn/news/387258.html

相关文章:

  • Linux常用命令大全(超详细!!!)
  • TDD测试驱动开发
  • huggingface镜像站
  • Java中如何实现数据库连接池优化?
  • 002 SpringMVC入门项目搭建
  • 为什么要使用多线程(并发编程)
  • Unity编辑器工具---版本控制与自动化打包工具
  • amis-editor 注册自定义组件
  • (上位机APP开发)调用华为云命令API接口给设备下发命令
  • 排序算法系列一:选择排序、插入排序 与 希尔排序
  • 【快速排序】| 详解快速排序 力扣912
  • 游戏推荐: 植物大战僵尸杂交版
  • 微调和rag的区别?
  • CVPR讲座总结(二)-探索图像生成基础模型的最新进展探索多模态代理的最新进展:从视频理解到可操作代理
  • 为什么要禁用透明大页面
  • Element 页面滚动表头置顶
  • 对于CDA一级考试该咋准备??!
  • 如何使用PHP和Selenium快速构建自己的网络爬虫系统
  • intellij idea安装R包ggplot2报错问题求解
  • 【C++】初识C++(一)
  • 【智能算法】目标检测算法
  • python 中 json.load json.loadd json.dump json.dumps 详解
  • 【UE 网络】专用服务器和多个客户端加入游戏会话的过程,以及GameMode、PlayerController、Pawn的创建流程
  • 磁盘分区工具(fdisk 和 parted)区别及操作笔记
  • VisualStudio2019受支持的.NET Core
  • Java——IO流(二)-(1/7):字符流-FileReader、FileWriter、字符输出流的注意事项(构造器及常用方法、小结)
  • Spring循环依赖问题——从源码画流程图
  • Android SurfaceFlinger——动画播放准备(十五)
  • Zynq7000系列FPGA中的DMA控制器简介(二)
  • 获取 url 地址栏 ? 后面的查询字符串,并以键值对形式放到对象里面