python-分析包依赖-pipreqs

安装

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即可。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值