查找python项目依赖并生成requirements.txt的方法
作者:orangleliu 时间:2021-11-27 20:41:43
一起开发项目的时候总是要搭建环境和部署环境的,这个时候必须得有个python第三方包的list,一般都叫做requirements.txt。 如果一个项目使用时virtualenv环境,还好办 pip freeze 就可以解决,但是如果一个项目的依赖list没有维护,而且又是环境混用,那就不好整理的呀,不过,这里安利一个工具 pipreqs,可以自动根据源码生成 requirements.txt .
使用pip freeze
$ pip freeze > requirements.txt
这种方式配合virtualenv 才好使,否则把整个环境中的包都列出来了。
使用 pipreqs
这个工具的好处是可以通过对项目目录的扫描,自动发现使用了那些类库,自动生成依赖清单。
缺点是可能会有些偏差,需要检查并自己调整下。
# pip install pipreqs
# 使用方式也比较简单
pipreqs ./
INFO: Starting new HTTPS connection (1): pypi.python.org
INFO: Starting new HTTPS connection (1): pypi.python.org
INFO: Starting new HTTPS connection (1): pypi.python.org
INFO: Starting new HTTPS connection (1): pypi.python.org
INFO: Starting new HTTPS connection (1): pypi.python.org
INFO: Starting new HTTPS connection (1): pypi.python.org
INFO: Successfully saved requirements file in ./requirements.txt
cat requirements.txt
Django == 1.6
django_redis == 4.3.0
redis == 2.10.5
django_redis_cache == 1.6.5
simplejson == 3.8.2
Twisted == 16.0.0
pycrypto == 2.6.1
ConcurrentLogHandler == 0.9.1
cx_Oracle == 5.2.1
ujson == 1.35
有时候结果可能会有些偏差,这里并没有用Oracle的相关驱动,根据的需要修改 requirements.txt 就好了。
how python project auto generate requirements.txt ?
来源:https://blog.csdn.net/orangleliu/article/details/60958525
标签:python,requirements
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
客户认同的就是好商品
2009-08-31 16:41:00
python调用Delphi写的Dll代码示例
2023-07-25 09:33:53
Python基于tkinter模块实现的改名小工具示例
2023-08-31 10:40:01
Python实现识别XSS漏洞的方法详解
2023-07-27 10:51:53
Python如何获取实时股票信息的方法示例
2021-10-13 19:45:54
Python中import导入上一级目录模块及循环import问题的解决
2021-09-16 00:53:44
Django权限系统auth模块用法解读
2021-03-22 13:27:00
python中map、any、all函数用法分析
2021-09-02 15:25:45
Python中for后接else的语法使用
2023-07-08 15:28:47
![](https://img.aspxhome.com/file/2023/8/64698_0s.jpg)
使用Python、TensorFlow和Keras来进行垃圾分类的操作方法
2021-08-31 23:45:13
window.open被浏览器拦截后的自定义提示
2007-11-23 12:31:00
Python中join和split用法实例
2021-09-01 21:18:55
深入解析PYTHON 虚拟机令人拍案叫绝的字节码设计
2023-09-02 16:13:21
![](https://img.aspxhome.com/file/2023/9/99209_0s.jpg)
link 和 style 元素在 HTML 文档中的位置
2008-06-02 13:56:00
良好体验,必须是全方位的
2009-09-24 13:32:00
![](https://img.aspxhome.com/file/UploadPic/20099/24/15-37s.png)
在django admin详情表单显示中添加自定义控件的实现
2023-09-24 18:56:00
浅析Python 中整型对象存储的位置
2021-10-06 13:40:20
asp如何显示全部的环境变量?
2010-06-08 09:34:00
python小项目之五子棋游戏
2022-07-12 06:24:23
![](https://img.aspxhome.com/file/2023/8/72848_0s.jpg)
Pandas中两个dataframe的交集和差集的示例代码
2022-05-24 14:52:37
![](https://img.aspxhome.com/file/2023/0/99470_0s.png)