python 3.7 import smbus ModuleNotFoundError no module named 'smbus'

Viewed 13842

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 <aurel32@debian.org>
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.

2 Answers

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.

I don't have a RPi to test this on, but when I was in HackerSpace I also built python on R-Pi. I ran into this exact same problem and found a fix that may work for you. You will need to open the config file: "sudo nano /boot/config.txt" and add the line "dtparam=i2c_arm=on" after you save it run "sudo raspi-config". Under advanced options you will find 7l2c select "Yes".

Related