查找python项目依赖并生成requirements.txt

发布时间:2019-08-05 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了查找python项目依赖并生成requirements.txt脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

多人一起开发项目的时候总是要搭建环境和部署环境的,这个时候必须得有个python第三方包的list,一般都叫做requirements.txt。 如果一个项目使用时virtualenv环境,还好办 pip freeze 就可以解决,但是如果一个项目的依赖list没有维护,而且又是环境混用,那就不好整理。不过,这里推荐一个python模块piPReqs,可以自动根据码生成 requirements.txt

使用pip freeze生成requirements.txt

 pip freeze > requirements.txt

使用 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

chardet==2.0.1
colorama==0.2.5
configobj==4.7.2
Django==1.11.10
djangorestframework==3.7.7
gunicorn==19.7.1
htML5lib==0.999
jieba==0.39
LandscaPE-Client==14.12
MySQL-python==1.2.3
numpy==1.14.0
PAM==0.4.2
pandas==0.22.0
Pillow==5.0.0
PyMySQL==0.8.0
pyOpenSSL==0.13
pyserial==2.6
python-apt===0.9.3.5ubuntu2
python-dateutil==2.6.1
python-Debian===0.1.21-nmu2ubuntu2
python-igraph==0.6.5
pytz==2017.3
redis==2.10.6
requests==2.2.1
six==1.5.2
ssh-import-id==3.21
Twisted-Core==13.2.0
urllib3==1.7.1
zope.interface==4.0.5

原文网址:http://www.chenxm.cc/post/538...

脚本宝典总结

以上是脚本宝典为你收集整理的查找python项目依赖并生成requirements.txt全部内容,希望文章能够帮你解决查找python项目依赖并生成requirements.txt所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。