安装
pip install pipreqs
使用
进入项目目录
(base)E:\files\codes>pipreqs .
INFO: Not scanning for jupyter notebooks.
WARNING: Import named "Bio" not found locally. Trying to resolve it at the PyPI server.
WARNING: Import named "Bio" was resolved to "bio:1.7.1" package (https://pypi.org/project/bio/).
Please, verify manually the final list of requirements.txt to avoid possible dependency confusions.
INFO: Successfully saved requirements file in .\requirements.txt
此时,当前目录下会出现一个文件requirements.txt,里面有所有python脚本使用的包以及包的版本(当前环境下的包的版本号)。
需要注意的是,如果有脚本的编码是GB2312,会报错:
Traceback (most recent call last):
File "D:\ProgramData\Anaconda3\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "D:\ProgramData\Anaconda3\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Users\xxx\AppData\Roaming\Python\Python39\Scripts\pipreqs.exe\__main__.py", line 7, in <module>
File "C:\Users\xxx\AppData\Roaming\Python\Python39\site-packages\pipreqs\pipreqs.py", line 609, in main
init(args)
File "C:\Users\xxx\AppData\Roaming\Python\Python39\site-packages\pipreqs\pipreqs.py", line 533, in init
candidates = get_all_imports(
File "C:\Users\xxxAppData\Roaming\Python\Python39\site-packages\pipreqs\pipreqs.py", line 136, in get_all_imports
contents = read_file_content(file_name, encoding)
File "C:\Users\xxx\AppData\Roaming\Python\Python39\site-packages\pipreqs\pipreqs.py", line 181, in read_file_content
contents = f.read()
File "D:\ProgramData\Anaconda3\lib\codecs.py", line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd7 in position 778: invalid continuation byte
这是因为无法解码,用Notepad++之类的编辑器,将编码改为utf-8即可。