Grove SGP30 Issues

I am following your directions on this link. I am using a Grove Base hat and a Raspberry Pi. I have followed the directions exactly but I always get an error message when I Import Seeed_SGP30.

Traceback (most recent call last):
File “test”, line 1, in
import seeed_sgp30
File “/home/pi/.local/lib/python3.7/site-packages/seeed_sgp30.py”, line 1, in
from sgp30 import Sgp30
File “/usr/local/lib/python3.7/dist-packages/sgp30/init.py”, line 1, in
from .sgp30 import Sgp30
File “/usr/local/lib/python3.7/dist-packages/sgp30/sgp30.py”, line 2, in
from smbus2 import SMBusWrapper, SMBus, i2c_msg

After looking at documentation for the smbus2 that this code uses it does not look like there is a SMBusWrapper for the smbus2. I am unable to edit this out of the code. What should I do?

@Brett_Biermann I think you missing this library.

sudo apt install python3-smbus 

I solved the issue installing the 0.2.0 version of smbus2 with the command:

pip install smbus2==0.2.0

Sorry for reviving, but neither way worked for me.

I have found other people asking this question, no to avail and no solution.

HELP! :slight_smile:

Have you checked the version number of the smbus library?

Hey :slight_smile:

Thanks for answering.

I did a lot of stuff yesterday, including several (re-)installs of packages, python2/3 etc.

Today I set up a pristine Raspi 4 for this with an untouched Raspian OS desktop image.

Same error.

Could you lead me to what you mean by smbus version? apt-based python-smbus or python3-smbus2? Anything else?

Sorry, I am completely out of ideas. I am not as dumb as I may sound, it’s just that python is about the one “dark spot” on my map for years… I have followed the sparse info about this problem, including pip’ing smbus or whatever that was :slight_smile:

I did not find anything “amiss” and I also set $PYTHONPATH once, afterwards, but maybe in a wrong way?

PS:

root@raspberrypi:/home/pi# dpkg -l | grep -i smbus ii python-smbus:armhf 4.1-1 armhf Python bindings for Linux SMBus access through i2c-dev ii python3-smbus:armhf 4.1-1 armhf Python 3 bindings for Linux SMBus access through i2c-dev

PPS:

pi@raspberrypi:~/HAT/Seeed_Python_SGP30/examples $ python sgp30_simpleread.py                                                              Traceback (most recent call last):                                                                                                           File "sgp30_simpleread.py", line 1, in <module>                                                                                              from sgp30 import Sgp30                                                                                                                  File "/usr/local/lib/python2.7/dist-packages/sgp30/__init__.py", line 1, in <module>                                                         from .sgp30 import Sgp30                                                                                                                 File "/usr/local/lib/python2.7/dist-packages/sgp30/sgp30.py", line 2, in <module>                                                            from smbus2 import SMBusWrapper, SMBus, i2c_msg                                                                                        ImportError: cannot import name SMBusWrapper


pip3 list:

-->> 
Package           Version                                                                                                                  ----------------- -----------                                                                                                              asn1crypto        0.24.0                                                                                                                   astroid           2.1.0                                                                                                                    asttokens         1.1.13                                                                                                                   automationhat     0.2.0                                                                                                                    beautifulsoup4    4.7.1                                                                                                                    blinker           1.4                                                                                                                      blinkt            0.1.2                                                                                                                    bme680            1.1.1                                                                                                                    buttonshim        0.0.2                                                                                                                    Cap1xxx           0.1.3                                                                                                                    certifi           2018.8.24                                                                                                                chardet           3.0.4                                                                                                                    Click             7.0                                                                                                                      colorama          0.3.7                                                                                                                    colorzero         1.1                                                                                                                      cookies           2.2.1                                                                                                                    cryptography      2.6.1                                                                                                                    cupshelpers       1.0                                                                                                                      docutils          0.14                                                                                                                     drumhat           0.1.0                                                                                                                    entrypoints       0.3                                                                                                                      envirophat        1.0.0                                                                                                                    ExplorerHAT       0.4.2                                                                                                                    Flask             1.0.2                                                                                                                    fourletterphat    0.1.0                                                                                                                    gpiozero          1.6.2                                                                                                                    grove.py          0.6                                                                                                                      html5lib          1.0.1                                                                                                                    idna              2.6                                                                                                                      isort             4.3.4                                                                                                                    itsdangerous      0.24                                                                                                                     jedi              0.13.2                                                                                                                   Jinja2            2.10                                                                                                                     keyring           17.1.1                                                                                                                   keyrings.alt      3.1.1                                                                                                                    lazy-object-proxy 1.3.1                                                                                                                    logilab-common    1.4.2                                                                                                                    lxml              4.3.2                                                                                                                    MarkupSafe        1.1.0                                                                                                                    mccabe            0.6.1                                                                                                                    microdotphat      0.2.1                                                                                                                    mote              0.0.4                                                                                                                    motephat          0.0.3                                                                                                                    mypy              0.670                                                                                                                    mypy-extensions   0.4.1                                                                                                                    numpy             1.16.2                                                                                                                   oauthlib          2.1.0                                                                                                                    olefile           0.46                                                                                                                     pantilthat        0.0.7                                                                                                                    parso             0.3.1                                                                                                                    pexpect           4.6.0                                                                                                                    pgzero            1.2                                                                                                                      phatbeat          0.1.1                                                                                                                    pianohat          0.1.0                                                                                                                    picamera          1.13                                                                                                                     piglow            1.2.5                                                                                                                    pigpio            1.78                                                                                                                     Pillow            5.4.1                                                                                                                    pip               18.1                                                                                                                     psutil            5.5.1                                                                                                                    pycairo           1.16.2                                                                                                                   pycrypto          2.6.1                                                                                                                    pycups            1.9.73                                                                                                                   pygame            1.9.4.post1                                                                                                              Pygments          2.3.1                                                                                                                    PyGObject         3.30.4                                                                                                                   pyinotify         0.9.6                                                                                                                    PyJWT             1.7.0                                                                                                                    pylint            2.2.2                                                                                                                    pyOpenSSL         19.0.0                                                                                                                   pyserial          3.4                                                                                                                      pysmbc            1.0.15.6                                                                                                                 python-apt        1.8.4.3                                                                                                                  pyxdg             0.25                                                                                                                     rainbowhat        0.1.0                                                                                                                    reportlab         3.5.13                                                                                                                   requests          2.21.0                                                                                                                   requests-oauthlib 1.0.0                                                                                                                    responses         0.9.0                                                                                                                    roman             2.0.0                                                                                                                    rpi-vl53l0x       0.0.3                                                                                                                    rpi-ws281x        4.3.1                                                                                                                    RPi.GPIO          0.7.0                                                                                                                    RTIMULib          7.2.1                                                                                                                    scrollphat        0.0.7                                                                                                                    scrollphathd      1.2.1                                                                                                                    SecretStorage     2.3.1                                                                                                                    Send2Trash        1.5.0                                                                                                                    sense-hat         2.2.0                                                                                                                    setuptools        40.8.0                                                                                                                   sgp30             0.1.6                                                                                                                    simplejson        3.16.0                                                                                                                   six               1.12.0                                                                                                                   skywriter         0.0.7                                                                                                                    smbus             1.1.post2                                                                                                                smbus2            0.4.1                                                                                                                    sn3218            1.2.7                                                                                                                    soupsieve         1.8                                                                                                                      spidev            3.5                                                                                                                      ssh-import-id     5.7                                                                                                                      thonny            3.3.10                                                                                                                   touchphat         0.0.1                                                                                                                    twython           3.7.0                                                                                                                    typed-ast         1.3.1                                                                                                                    unicornhathd      0.0.4                                                                                                                    urllib3           1.24.1                                                                                                                   webencodings      0.5.1                                                                                                                    Werkzeug          0.14.1                                                                                                                   wheel             0.32.3                                                                                                                   wrapt             1.10.11 

<–

Because our engineers also mentioned that a certain version of smbus is needed to solve this problem, so I need to know whether you have successfully installed this module and run it. Obtaining its version number information is the most direct way. You can refer to the following website to troubleshoot the problem first.

Thanks for answering, the given website is not really helpful for someone without python experience to find out which version number is installed or used. Problem: I got no clue if apt packages differ from pip installed packages etc.

I upgraded to raspbian os bullseye in order to find out if there’s a solution. When running the VOC package as described at

then doing as advised by the wiki:

cd Seeed_Python_SGP30
sudo python setup.py install

There’s a short mention of the installed python-smbus2 package:

Best match: smbus2 0.4.1 Adding smbus2 0.4.1 to easy-install.pth file

Running the example script throws the same error as before, though:

||cd examples|
||python sgp30_simpleread.py|

Traceback (most recent call last): File “/home/pi/HAT/Seeed_Python_SGP30/examples/sgp30_simpleread.py”, line 1, in import seeed_sgp30 File “”, line 259, in load_module File “/usr/local/lib/python3.9/dist-packages/seeed_python_sgp30-0.0.0-py3.9.egg/seeed_sgp30.py”, line 1, in File “/usr/local/lib/python3.9/dist-packages/sgp30-0.1.6-py3.9.egg/sgp30/init.py”, line 1, in from .sgp30 import Sgp30 File “/usr/local/lib/python3.9/dist-packages/sgp30-0.1.6-py3.9.egg/sgp30/sgp30.py”, line 2, in from smbus2 import SMBusWrapper, SMBus, i2c_msg ImportError: cannot import name ‘SMBusWrapper’ from ‘smbus2’ (/usr/local/lib/python3.9/dist-packages/smbus2/init

Could you ask your engineers, which version numbers and which combination in terms of installers should work, please?

I really wonder why this problem occurs on a default raspbian os installation, this sensor should be quite widespread and so should be the error as I followed the wiki standard installation instructions…?!

I can’t really believe there’s no one who’s using this sensor and experiencing the same problem.

I just set up another Raspi 4 with buster with the same result…

I am having exactly the same issue. New 4, new (reformatted) SD card.

OK - this is a non-trival problem I think. There is no SMBusWrapper class/object in smbus2 - I think it’s been removed as per:

This means that sgp30.py (which is the script that requires SMBusWrapper) won’t work and that anything that tries to import SMBusWrapper from smbus2 will fall over.

Confirmed here:

Looks like a simple solution though - I will implement and let you know!

UPDATE: now working.

You’ll need to edit sgp30.py to remove any reference to SMBusWrapper and replace (where needed) with SMBus. Anything that calls or imports smbus2.SMBusWrapper needs to be changed too.

1 Like

Thanks a lot, volcanologist!

I had given up hope for an answer from Seeed, so it took some time to come back here, for me :slight_smile:

I tried your solution, but I’m still stuck as now the HAT script demands:

rpi.gpio-common (= 0.7.0-0.1~bpo10+4)

but

0.7.0-0.2+b1

shall be installed. I could cope with that, but it’s inside the curl’d installation script.

I am slowly running out of love for Grove…

Hi everyone, we are working hard to fix this, please wait

The solutions we have so far are as follows:
Follow the steps of our wiki to run the program first, but finally execute the code using:
python3 sgp30_simpleread.py instead of python sgp30_simpleread.py
Then get the address of the program error, we enter this directory and use
sudo nano ~/sgp30.py
Modify the second line of the code and delete the SMBusWrapper.
Save and re-execute python3 sgp30_simpleread.py

We have updated the latest tutorial documentation on the wiki, thank you for your efforts to improve our product documentation, and once again apologize for the inconvenience caused to you.

I appreciate your work and the solution, but I am still stuck when trying to follow the instructions on the wiki page

First step calls for

curl -sL https://github.com/Seeed-Studio/grove.py/raw/master/install.sh | sudo bash -s -

to be executed. This script fails with an error:

python-rpi.gpio no installation candidate

(As described above…)

If you can’t install the above method, you can refer to the wiki for another installation method:Step by step installation