首页 > 解决方案 > 'can' BLFReader 函数的 Python 属性错误

问题描述

Python 3.9.4 (tags/v3.9.4:1f2e308, Apr  6 2021, 13:40:21) [MSC v.1928 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import can
>>> filename = "test.blf"
>>> log = can.BLFReader(filename)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'can' has no attribute 'BLFReader'
>>>

我正在尝试使用 Python 导入 CAN blf 文件。

我使用了 can 模块和 BLFReader 函数,但它显示属性错误如上。

我的 python 版本是 3.9.4。

我该如何解决这个问题?

标签: pythonattributeerror

解决方案


BLFReader在包中python-can,不在can包中。

卸载can并安装python-can

pip3 uninstall can
pip3 install python-can

然后:

import can
can.BLFReader

# <class 'can.io.blf.BLFReader'>


推荐阅读