Python 依赖库管理pip、pipreqs、pigar、pip-tools、pipdeptree
发布日期:2021-07-01 06:08:10
浏览次数:2
分类:技术文章
本文共 1458 字,大约阅读时间需要 4 分钟。
准备一个main.py文件
# -*- coding: utf-8 -*-import mysql.connectorimport flaskfrom bs4 import BeautifulSoup
一、pip
搜索全局环境依赖库
导出依赖
$ pip freeze > requirements.txtmysql-connector-python==8.0.17Flask==1.1.1beautifulsoup4==4.8.1Django==2.2.5...# 省略剩下的依赖库
依赖的全称是对的
二、pipreqs
基于目录的方式搜索依赖库,搜索的依据是脚本中所 import 的内容
安装
pip install pipreqs
导出依赖
$ pipreqs --forceFlask==1.1.1beautifulsoup4==4.8.1mysql_connector_repackaged==0.3.1
库 mysql-connector-python==8.0.17
被导出成了 mysql_connector_repackaged==0.3.1
三、pigar
根据项目路径来生成依赖文件, 而且会列出依赖库在文件中哪些位置使用到了
安装
pip install pigar
查询真实来源
$ pigar -s bs4==================================PACKAGE | VERSION | WHERE---------------+---------+------beautifulsoup4 | 4.8.1 | local==================================
导出依赖
$ pigar# Requirements automatically generated by pigar.# https://github.com/damnever/pigar# main.py: 4Flask == 1.1.1# main.py: 5beautifulsoup4 == 4.8.1# main.py: 3mysql_connector_python == 8.0.17
四、pip-tools
精准地控制项目的依赖库
安装
pip install pip-tools
新建 requirements.ini
Flask
生成依赖文件
$ pip-compile requirements.ini## This file is autogenerated by pip-compile# To update, run:## pip-compile requirements.ini#--index-url https://pypi.tuna.tsinghua.edu.cn/simpleflask==1.1.1
同步依赖文件
$ pip-sync requirements.txt# 注意,不在requirements.txt 文件中的库会被卸载
五、pipdeptree
生成依赖树
安装
pip install pipdeptree
生成依赖树文件
$ pipdeptree --freeze > requirements.txtFlask==1.1.1 Click==7.0 itsdangerous Jinja2 Werkzeugsetuptools==41.0.1wheel==0.33.4
参考
转载地址:https://pengshiyu.blog.csdn.net/article/details/103197127 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
关注你微信了!
[***.104.42.241]2024年04月10日 09时40分21秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
Html5学习笔记(一)
2019-05-08
Nginx在linux平台部署 的运行优化原理
2019-05-08
git 代理设置
2019-05-08
Websocket Frame 格式(Websocket 数据帧格式)
2019-05-08
高性能异步 I/O 模型库 libuv 设计思路概述
2019-05-08
linux系统常用命令使用说明
2019-05-08
jQuery性能优化注意事项
2019-05-08
Webrtc 中的SDP协议字段解释
2019-05-08
OPENSSL BIO服务器端伪代码
2019-05-08
用nginx反向代理功能将WS转为加密websocket (wss)
2019-05-08
CentOS 安装java 运行环境
2019-05-08
云服务器上的CentOS6 安装 Python3.8.4
2019-05-08
Nginx 关闭静态文件与某个目录或连接的访问日志
2019-05-08
RTMP 推流认证的 adobe 用户认证原理与过程介绍
2019-05-08
javascript 的Uint8Array 构造函数对 typedArray的引用问题
2019-05-08
谷歌浏览器 Chrome 最新版离线安装包下载地址
2019-05-08