当需要生成某个项目所需要的包以及相应的版本,可以先cd到项目目录,然后输入:
pipreqs ./
报编码错误,如下:
Traceback (most recent call last):
File "f:\users\asus\anaconda3\lib\runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "f:\users\asus\anaconda3\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "F:\Users\asus\Anaconda3\Scripts\pipreqs.exe\__main__.py", line 7, in <module>
File "f:\users\asus\anaconda3\lib\site-packages\pipreqs\pipreqs.py", line 470, in main
init(args)
File "f:\users\asus\anaconda3\lib\site-packages\pipreqs\pipreqs.py", line 409, in init
follow_links=follow_links)
File "f:\users\asus\anaconda3\lib\site-packages\pipreqs\pipreqs.py", line 122, in get_all_imports
contents = f.read()
File "f:\users\asus\anaconda3\lib\codecs.py", line 321, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xbb in position 570: invalid start byte
找到pipreqs.py第122行,修改编码格式为ISO-8859-1即可。
with open_func(file_name, "r", encoding='ISO-8859-1') as f:
contents = f.read()
尝试了很多编码格式,比如gbk,gb18030等等还是报错,直到用ISO-8859-1才行。具体原因是因为decode的参数设置过于严格,设置为igonre,但是也没找到decode函数在哪里更改。后续找到了再来更改吧。