bme280: 'load_calibration_params' problem when running script

Traceback (most recent call last): File "sensor.py", line 8, in <module> calibration_params = bme280.load_calibration_params(bus, address) AttributeError: 'module' object has no attribute 'load_calibration_params' This is the problem I get when running my script for my weather station. It is a python script but for the sake to get it uploaded with github’s limited file extensions I made it a text file bme280_sensor.txt

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 1
  • Comments: 27 (4 by maintainers)

Most upvoted comments

Ok, my bad… test file was named “bme280.py” and this was a problem, just renaming file to “bme280test.py” fix this problem

Does anyone know what should I get when doing “sudo pip install RPi.bme280”?

You can find location for a python package with pip show RPi.bme280 if the package installed already. For me it shows:

$ pip3 show RPi.bme280
Name: RPi.bme280
Version: 0.2.3
Summary: A library to drive a Bosch BME280 temperature, humidity, pressure sensor over I2C
Home-page: https://github.com/rm-hull/bme280
Author: Richard Hull
Author-email: richard.hull@destructuring-bind.org
License: MIT
Location: /home/boris/.local/lib/python3.7/site-packages
Requires: smbus2
Required-by: 

Two notions may be important at the moment:

  1. pip and pip3 are different for python versions 2 and 3. I suggest you should use pip3
  2. I bielieve the sudo is unnecessary here for package installation. Packages should be installed into your user`s home location to be discovered when imported in script.

Then take a look into the file:

$ cat ~/.local/lib/python3.7/site-packages/RPi.bme280-0.2.3.dist-info/RECORD 
RPi.bme280-0.2.3.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
RPi.bme280-0.2.3.dist-info/LICENSE.rst,sha256=-gH_h4n_d6h1BlWvRB80q5AZDIpnyyZOxH5q3bD5wyg,1081
RPi.bme280-0.2.3.dist-info/METADATA,sha256=CdHuDhiUSdr3WZiQOebvdA_7VunRMQGjyEmXp9p-_Qs,7977
RPi.bme280-0.2.3.dist-info/RECORD,,
RPi.bme280-0.2.3.dist-info/WHEEL,sha256=CihQvCnsGZQBGAHLEUMf0IdA4fRduS_NBUTMgCTtvPM,110
RPi.bme280-0.2.3.dist-info/top_level.txt,sha256=akOWEt2_vXS0A30sKz_7dK2a9D0myQsD5EnnXQuL5SU,7
bme280/__init__.py,sha256=gUyS7D2h8-vK-40QePKiP1nEFBb0mwA2JqHms2_paSs,8317
bme280/__pycache__/__init__.cpython-37.pyc,,
bme280/__pycache__/const.cpython-37.pyc,,
bme280/__pycache__/reader.cpython-37.pyc,,
bme280/const.py,sha256=rdtvBiVropTbphcdzPY-9nezuZvG5sEh9si9H__b4NY,1699
bme280/reader.py,sha256=7SkZpDpkmh6P4Q5l_LR8wAjCy9xoEcht7aWUrBOMWxA,1971

It shows pyc-files located at bme280 dir located at ~/.local/lib/python3.7/site-packages/. The code to be imported is contained there.

So, after all verified you should be able to import ‘bme280’ module in pytohn3

Thank you very much Boris! Until today I had no time to test what you said. Now it works!

Funny I have the same issue. Although it’s not related to my naming of my python script as I’m using the ‘sample.py’ supplied.

If I attempt to run the ‘sample.py’ script from the directory /home/pi/bme280/examples it fails with the error :-

python sample.py Traceback (most recent call last): File "sample.py", line 13, in <module> calibration_params = bme280.load_calibration_params(bus, address) AttributeError: 'module' object has no attribute 'load_calibration_params'

however, if I copy the code to the directory /home/pi/bme280 it works fine :-

python sample.py compensation_params = {'dig_H1': 75, 'dig_H3': 0, 'dig_H2': 386, 'dig_H5': 50, 'dig_H4': 264, 'dig_H6': '30, 'dig_P9': 4285, 'dig_P8': -10230, 'dig_T1': 28383, 'dig_T3': 50, 'dig_T2': 26590, 'dig_P1': 35048, 'dig_P3': 3024, 'dig_P2': -10521, 'dig_P5': 15, 'dig_P4': 6438, 'dig_P7': 9900, 'dig_P6': -7} uncompensated_reading(temp=0x0007F3A0, pressure=0x0005EBD0, humidity=0x00005F53, block=5E:BD:00:7F:3A:00:5F:53) compensated_reading(id=a7d93be9-635b-4f26-b4e3-5d733c21db29, timestamp=2019-12-22 15:21:27.399743UTC, temp=21.238 °C, pressure=987.47 hPa, humidity=43.98 % rH)

Trying to run the code outside of the bme280 directory fails for me completely.

It seems to me that you need the a directory called ‘bme280’ in your current directory with the files “const.py const.pyc init.py init.pyc reader.py reader.pyc” in it.

I competely uninstalled and just installed it from pip. The it doesn’t work at all as no where do you have the files it seems to require. Seems something is missing during the install.