python 3.7 import smbus ModuleNotFoundError no module named 'smbus'

Garry Osborne picture Garry Osborne · Sep 8, 2018 · Viewed 10.7k times · Source

I successfully built python 3.7 on my raspberry pi zero. now when I run my program using:

python3 DungeonCube.py

I get the following error:

import smbus
ModuleFoundError: No module named 'smbus'

I have searched for solutions and it seems no one has gotten this far with python 3.7 on a raspberry pi. other guides say to reinstall smbus or install smbus2 and that does not work.

dpkg-query -L python3-smbus shows:

/.
/usr
/usr/lib
/usr/lib/python3
/usr/lib/python3/dist-packages
/usr/lib/python3/dist-packages/smbus.cpython-35m-arm- 
linux-gnueabihf.so
/usr/share
/usr/share/doc
/usr/share/doc/python3-smbus
/usr/share/doc/python3-smbus/changelog.Debian.gz
/usr/share/doc/python3-smbus/changelog.gz
/usr/share/doc/python3-smbus/copyright

apt-cache show python3-smbus shows:

Package: python3-smbus
Version: 3.1.2-3
Architecture: armhf
Maintainer: Aurelien Jarno <[email protected]>
Installed-Size: 31
Depends: libc6 (>=2.4), python3 (<< 3.6), python3 (>= 
3.5~), python3:any (>= 3.0~)
Recommends: i2c-tools
Provides: python3.5-smbus
.
.
.

Any ideas how to get this working?

Garry O.

Answer

Laurent LAPORTE picture Laurent LAPORTE · Sep 8, 2018

The python3-smbus library which is installed on your system seems a little old. It works for Python 3.5 but not for Python 3.7.

You have two solutions:

  • downgrade your Python to use Python 3.5
  • choose another library: you can try smbus2 which is more uptodate.