晚上好,AttributeError的:“模块”对象有没有属性“的SMBus”
我一直在努力的SMBus通信到我的硬盘驱动器,并已能够通过所谓的readwriteeverything程序来读取值。现在,我想创建自己的程序来读取和写入python中的导入smbus的寄存器。所以,我决定立足我的代码从这个例子:
from smbus import SMBus
bus = SMBus(1) # 0 = /dev/i2c-0 (port I2C0), 1 = /dev/i2c-1 (port I2C1)
DEVICE_ADDRESS = 0x15 #7 bit address (will be left shifted to add the read write bit)
DEVICE_REG_MODE1 = 0x00
bus.write_data(DEVICE_ADDRESS, DEVICE_REG_MODE1)
bus.read_data(DEVICE_ADDRESS)
然而,当我尝试运行的一行代码:
from smbus import SMBus
我得到:
ImportError: cannot import name SMBus
我已经尝试了python2,python3,安装了很多软件包,比如python3-smbus,甚至试图构建软件包并安装它(尽管这是基于Raspberry Pi指南并且是与桌面相关的)。
我试过在Windows和Linux上都遇到同样的问题。
如何让这个命令正常工作?
的细节,你试过通过PIP安装呢? – Natecat
是的,我尝试按照这个指南:https://pypi.python.org/pypi/smbus-cffi,仍然没有运气 –