Python 生成项目的 requirements.txt 文件
1、freeze
说明: 它生成的 requirements.txt 文件包含当前环境的完全列表,不相关的依赖包也会包含进来,**注意这个库生成的requirements.txt会包含整个当前环境下的所有库。**但是呢,如果我们想要的是生成一个项目环境下的库,所以这个freeze就不太合适了。
安装:
pip install freeze
使用-生成rrequirements.txt:
#注意先cd到项目所在的目录下哈
pip freeze > requirements.txt
使用-安装requirements.txt中的类库:
pip install -r requirements.txt
2、pipreqs
pipreqs可以通过对项目目录的扫描,自动发现使用了那些类库,自动生成依赖清单,只生成项目相关的依赖到requirements.txt
安装:
pip install pipreqs
pip的freeze命令只保存与安装在您的环境python所有软件包。
但有时你只想将当前项目使用的类库导出生成为 requirements.txt;
使用方法:pipreqs 加上当前路径即可。
pipreqs ./path
但是我使用的时候竟然报错
使用网上的方法将encoding该为utf-8没有卵用
结果——没有结果,我才浪费时间解决的。——赶紧换其他方法。
https://www.cnblogs.com/jiangchunsheng/p/9317820.html
3、pigar--------推荐使用
安装:
pip install pigar
使用方法:
输出信息比 pipgreqs 详细
-h, --help show this help message and exit
-v, --version show pigar version information and exit
-u, --update update database, use it when pigar failed you, exit when
action done
-s NAME [NAME ...] search package name by import name, use it if you do not
know import name come from which package, exit when
action done
-c [PATH] check requirements for the latest version. If file path
not given, search *requirements.txt in current
directory, if not found, generate file requirements.txt,
exit when action done
-l LOG_LEVEL show given level log messages, argument can be (ERROR,
WARNING, INFO), case-insensitive
-i DIR [DIR ...] given a list of directory to ignore, relative directory,
*used for* -c and default action
-p SAVE_PATH save requirements in given file path, *used for* default
action
-P PROJECT_PATH project path, which is directory, *used for* default
action
应用:
pigar -c C:\Users\zmj25\PycharmProjects\confusion\classification_eval
是不是非常详细,哈哈哈