晚上好,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,仍然沒有運氣 –