python-3.x - RPI3B BME280 属性错误 : 'module' object has no attribute 'load_calibration_params'

标签 python-3.x raspberry-pi3

在与 smbus2 错误作斗争后,我试图让以下代码正常工作,我现在发现我有以下错误,但找不到如何修复它。

我知道传感器正在工作,因为如果我从 http://www.raspberrypi-spy.co.uk/ 运行 bme280.py没问题。

所以我的错误是:

pi@wpi:~/weather $ python bme280_sensor.py
Traceback (most recent call last):
  File "bme280_sensor.py", line 9, in <module>
    bme280.load_calibration_params(bus, address)
AttributeError: 'module' object has no attribute 'load_calibration_params'


i2detect 
pi@wpi:~/weather $ i2cdetect -y 1
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- 76 --

代码无效:来自 https://pypi.org/project/RPi.bme280/

import smbus2
import bme280

port = 1
address = 0x76
bus = smbus2.SMBus(port)

calibration_params = bme280.load_calibration_params(bus, address)

# the sample method will take a single reading and return a
# compensated_reading object
data = bme280.sample(bus, address, calibration_params)

# the compensated_reading class has the following attributes
print(data.id)
print(data.timestamp)
print(data.temperature)
print(data.pressure)
print(data.humidity)

# there is a handy string representation too
print(data)

最佳答案

发现我的问题,将其发布在这里,以防其他新手遇到同样的问题!

我在同一文件夹中有一个名为 bme280.py 的文件,因此它正在加载该文件而不是正确的 bme280 库。

解决方案只是重命名该文件。

关于python-3.x - RPI3B BME280 属性错误 : 'module' object has no attribute 'load_calibration_params' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53686612/

相关文章:

python - 在单行文本文件中的数字后添加新行

python - 即使在更改代码后,AWS Lambda python 函数输出仍然是 "Hello from Lambda"

python - OpenGL 中的等距 View

bluetooth - 如何设置 Bluez 5 以在配对期间询问密码

c - C 中的 CTRL+C 上的 Raspberry Pi 干净退出

Python数据框匹配列表中的字符串

mysql - 在 Python 中使用 mysql.connector 执行 MySQL 触发器,该触发器计算值并将其插入到现有表中新创建的列中

python-3.x - 当 stdout 重定向到文件时,Python 脚本不写入任何输出

mariadb - 如何交叉编译安装了 mariadb10 的 RPI3(Stretch)以与 QTCreator 一起使用?

node.js - NodeJS : Async/Await Raspberry Pi