Wrong python version used with smbus2?

108 views
Skip to first unread message

Guido Cioni

unread,
Jul 11, 2022, 1:21:49 PM7/11/22
to weewx-user
I'm trying to add the BME280 sensor with the https://gitlab.com/wjcarpenter/bme280wx plugin. I installed all required dependencies and verified that the data are correctly read using a python script containing

import smbus2 

which I invoke as python test.py
I have only 1 version of python installed in this system, that is this python linked to python3

pi@weather:~ $ python
Python 3.9.2 (default, Feb 28 2021, 17:03:44)
[GCC 10.2.1 20210110] on linux

It has smbus2 installed 

pi@weather:~ $ pip list
Package       Version
------------- ---------
....
smbus2        0.4.2
....

this is apparently the same Python version  used by weewx 

Jul 11 19:11:27 weather weewx[2704] INFO __main__: Using Python 3.9.2 (default, Feb 28 2021, 17:03:44) #012[GCC 10.2.1 20210110]

However this fails to import smbus2 

Jul 11 19:11:27 weather weewx[2707] DEBUG weewx.engine: Loading service user.bme280wx.Bme280wx
Jul 11 19:11:27 weather weewx[2707] CRITICAL __main__: Caught unrecoverable exception:
Jul 11 19:11:27 weather weewx[2707] CRITICAL __main__:     ****  No module named 'smbus2'
Jul 11 19:11:27 weather weewx[2707] CRITICAL __main__:     ****  Traceback (most recent call last):
Jul 11 19:11:27 weather weewx[2707] CRITICAL __main__:     ****    File "/usr/share/weewx/weewxd", line 147, in main
Jul 11 19:11:27 weather weewx[2707] CRITICAL __main__:     ****      engine = weewx.engine.StdEngine(config_dict)
Jul 11 19:11:27 weather weewx[2707] CRITICAL __main__:     ****    File "/usr/share/weewx/weewx/engine.py", line 93, in __init__
Jul 11 19:11:27 weather weewx[2707] CRITICAL __main__:     ****      self.loadServices(config_dict)
Jul 11 19:11:27 weather weewx[2707] CRITICAL __main__:     ****    File "/usr/share/weewx/weewx/engine.py", line 161, in loadServices
Jul 11 19:11:27 weather weewx[2707] CRITICAL __main__:     ****      obj = weeutil.weeutil.get_object(svc)(self, config_dict)
Jul 11 19:11:27 weather weewx[2707] CRITICAL __main__:     ****    File "/usr/share/weewx/weeutil/weeutil.py", line 1150, in get_object
Jul 11 19:11:27 weather weewx[2707] CRITICAL __main__:     ****      mod = __import__(module)
Jul 11 19:11:27 weather weewx[2707] CRITICAL __main__:     ****    File "/usr/share/weewx/user/bme280wx.py", line 5, in <module>
Jul 11 19:11:27 weather weewx[2707] CRITICAL __main__:     ****      import smbus2
Jul 11 19:11:27 weather weewx[2707] CRITICAL __main__:     ****  ModuleNotFoundError: No module named 'smbus2'
Jul 11 19:11:27 weather weewx[2707] CRITICAL __main__:     ****  Exiting.


I'm really puzzled...which version of Python is weewx using? 

Guido Cioni

unread,
Jul 11, 2022, 2:02:37 PM7/11/22
to weewx-user
Ok I figured out that those libraries need to be installed in the python3 of sudo, because weewx is starting as sudo...
Not sure if this is the default behaviour or not 

Reply all
Reply to author
Forward
0 new messages