查找python项目依赖并生成requirements.txt的方法
2019/7/15 0:31:56
本文主要是介绍查找python项目依赖并生成requirements.txt的方法,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
一起开发项目的时候总是要搭建环境和部署环境的,这个时候必须得有个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 ?
以上这篇查找python项目依赖并生成requirements.txt的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持找一找教程网。
这篇关于查找python项目依赖并生成requirements.txt的方法的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-08有遇到过吗?同样的规则 Excel 中 比Python 结果大
- 2024-03-30开始python成长之路
- 2024-03-29python optparse
- 2024-03-29python map 函数
- 2024-03-20invalid format specifier python
- 2024-03-18pool.map python
- 2024-03-18threads in python
- 2024-03-14python Ai 应用开发基础训练,字符串,字典,文件
- 2024-03-13id3 algorithm python
- 2024-03-13sum array elements python