一、背景
历史的python代码库或文件夹需要迁移,依赖的python第三方模块一个个安装也比较繁琐,期望可以快速获取到对应的第三方依赖模块列表。
二、解决方案
使用pipreqs库自动生成指定目录下第三方依赖模块文件requirements.txt。
安装pipreqs库
pip3 install pipreqs
直接在你的计划的目录下执行:
pipreqs
如果没有问题的话默认会在当前目录生成requirements.txt文件,我生成的文件如下:
$ cat requirements.txt elasticsearch==7.16.2 flask==2.0.1 flask_restful==0.3.9 json_tools==0.4.1 logzero==1.7.0 openpyxl==3.0.5 pandas==1.1.5 pymongo==3.11.0 redis==4.1.0 requests==2.27.1 xlrd==1.2.0 xlutils==2.0.0
三、问题记录
执行pipreqs报错
报错信息:
requests.exceptions.connectionerror: httpsconnectionpool(host='pypi.python.org', port=443): max retries exceeded with url: /pypi/elasticsearch/json (caused by newconnectionerror('<urllib3.connection.httpsconnection object at 0x7f1613f1b550>: failed to establish a new connection: [errno 110] connection timed out',))
解决办法:
使用国内的pypi镜像源,如阿里云或清华大学的镜像:
pipreqs --pypi-server https://pypi.tuna.tsinghua.edu.cn/simple /path/to/project
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。
发表评论