pip-入门操作简介

0.摘要

本文主要介绍pip的常用方法,基于python3环境。给出的命令是Linux的形式,windows的cmd中,需要去掉sudo,部分命令直接输入python即可,不需要输入python3。

 

1.pip版本升级

python -m pip install --upgrade pip 

 

2.安装库

一般安装方法,适用于大多数情况:pip install 库名称

指定使用python3对应的pip安装库:sudo python3 -m pip install 库名称

 

3.查看已安装的库,并更新

查看已安装的库:pip list

检查并显示已过期的库:pip list --outdated

更新指定库:pip install --upgrade 需要更新的库的名称

 

查看pip参数:

使用pip -help 即可查看,内容如下:

命令
installInstall packages
downloadDownload packages.
uninstallUninstall packages.
freezeOutput installed packages in requirements format.
listList installed packages.
showShow information about installed packages.
checkVerify installed packages have compatible dependencies.
configManage local and global configuration.
searchSearch PyPI for packages.
wheelBuild wheels from your requirements.
hashCompute hashes of package archives.
completionA helper command used for command completion.
helpShow help for commands.
常用操作
-h, --helpShow help.
--isolatedRun pip in an isolated mode, ignoring environment variables and user configuration.
 -v, --verboseGive more output. Option is additive, and can be used up to 3 times.
-V, --versionShow 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 6000.0 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-dirDisable the cache.
--disable-pip-version-checkDon'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

 

 

`pip-tools` 是一组用于处理 Python 包依赖关系的强大工具集,它可以帮助开发者更好地管理和维护项目的依赖项。下面将详细介绍如何使用 `pip-tools` 来简化依赖管理过程。 ### 安装 pip-tools 首先需要确保已经安装了 `pip-tools` ,可以通过以下命令来完成安装: ```bash pip install pip-tools ``` ### 使用步骤详解 #### 编写初始的 requirements.in 文件 在项目根目录下创建名为 `requirements.in` 的文件,并列出你的直接依赖包(仅限于顶级依赖)。例如: ```text # requirements.in flask>=2.0.0 requests==2.28.* ``` 注意这里只包含必要的、明确版本约束的依赖,而不需要写下间接引入的所有子依赖。 #### 生成完整的 dependencies 文件 (requirements.txt) 运行如下指令来自动生成详细的 `requirements.txt` 文件,其中包含了所有层级下的完整依赖树以及它们各自的兼容性版本范围: ```bash pip-compile ``` 这一步会读取 `requirements.in` 内容然后通过分析各库之间的相依关系得出最合理的组合形式存入到目标文件中去。 如果你想让其覆盖现有的同名文件,则添加 `-o|--output-file <file>` 参数指定输出路径,默认即为当前工作区内的 `requirements.txt`. 此外还可以加上 `--upgrade` 标志强制刷新已有条目的最佳匹配结果; ```bash pip-compile --upgrade ``` #### 同步实际环境与理论需求的一致性 最后一步就是保证本地虚拟环境中确实按照预期加载好了上述计算出的结果集合。为此我们借助另一个子命令 `pip-sync` 实现此操作: ```bash pip-sync requirements.txt ``` 该命令的作用类似于执行了一个干净彻底地卸载再全新安装的过程,因此务必小心对待生产线上正在服役的服务端实例! ### 常见选项补充说明 - **–find-links**: 指向自定义索引 URL 或者是离线仓库地址。 - **-U/--upgrade-package PKGS...**: 只针对给定名称列表里的那些包做单独升级动作而不影响其它部分。 - **-P/--pre**: 开启预发布版的支持开关允许引入 alpha/beta/candidate 等状态的新鲜玩意儿。 以上便是关于怎样高效运用 `pip-tools` 对日常开发过程中不可避免要面临的繁杂多变之第三方扩展组件进行有序治理的一个简短入门指南啦~
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值