djdan_23
Posts: 19
Joined: Thu Aug 17, 2017 1:42 am

No module named 'smbus' on Python3.6.2

Sun Sep 10, 2017 12:39 pm

Hi! all.
I have Raspberry pi3 with 32gb Sd Card.
Linux Kernel=4.9.41-v7+ #1026.
Firmware=Aug 8 2017 12:01:57 Copyright 2012 Broadcom.
Python=3.6.2 (Build last week) using http://bohdan-danishevsky.blogspot.ca/2 ... y-pi-3.htm
Raspbian GNU/Linux 9 (stretch).
I use: sudo apt-get update then sudo apt-get upgrade
then sudo apt-get install python3-smbus
that write: Reading package lists... Done
Building dependency tree
Reading state information... Done
python3-smbus is already the newest version (3.1.2-3).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgrade
Everything works properly.

I have hooked-up a Chronodot (RTC) on i2c bus. When I use i2cset.... or i2cget.... in terminal,
it work normally.
I've been told that I can't use those command in a scrip. So I have a scrip
that have only one line: import smbus

In version 2.7.13
When i use: python chronodot.py it pass thru OK.
In version 3.6.2
When i use: python3.6 chronodot.py it print:

Traceback (most recent call last):
File "chronodotz.py", line 1, in <module>
import smbus
ModuleNotFoundError: No module named 'smbus'


Could anyone tell me what is wrong. Thanks

User avatar
paddyg
Posts: 2123
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: No module named 'smbus' on Python3.6.2

Sun Sep 10, 2017 12:59 pm

viewtopic.php?f=32&t=122260 might be relevant (they seem to say you need to pip3 install it)
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

djdan_23
Posts: 19
Joined: Thu Aug 17, 2017 1:42 am

Re: No module named 'smbus' on Python3.6.2

Sun Sep 10, 2017 1:13 pm

Thanks. Here<s what I did.

$ sudo apt-get install python3-smbus
Reading package lists... Done
Building dependency tree
Reading state information... Done
python3-smbus is already the newest version (3.1.2-3).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

$ sudo aptitude search smbus
i python-smbus - Python bindings for Linux SMBus access thr
v python2.7-smbus -
i python3-smbus - Python 3 bindings for Linux SMBus access t
v python3.5-smbus -


$ sudo pip install smbus
Collecting smbus
Could not find a version that satisfies the requirement smbus (from versions: )
No matching distribution found for smbus

$ sudo pip3 install smbus
Collecting smbus
Could not find a version that satisfies the requirement smbus (from versions: )
No matching distribution found for smbus

The "could not find......." is in RED color

User avatar
paddyg
Posts: 2123
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: No module named 'smbus' on Python3.6.2

Sun Sep 10, 2017 1:19 pm

and did smbus2 (as per the bottom of the thread) not work?
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

djdan_23
Posts: 19
Joined: Thu Aug 17, 2017 1:42 am

Re: No module named 'smbus' on Python3.6.2

Sun Sep 10, 2017 1:38 pm

Here's the result

sudo pip install smbus2
Collecting smbus2
Downloading smbus2-0.2.0.tar.gz
Building wheels for collected packages: smbus2
Running setup.py bdist_wheel for smbus2 ... done
Stored in directory: /root/.cache/pip/wheels/90/71/b4/9f90d8e2d0349ab55fef07169a81bd8f925965f16174e2f809
Successfully built smbus2
Installing collected packages: smbus2
Successfully installed smbus2-0.2.0

python3.6 chronodot.py
Traceback (most recent call last):
File "chronodot.py", line 1, in <module>
import smbus2 as smbus
ModuleNotFoundError: No module named 'smbus2'

B.Goode
Posts: 6016
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: No module named 'smbus' on Python3.6.2

Sun Sep 10, 2017 2:26 pm

When you install with pip you make the package available to Python2.

To make the package available to Python3 it is necessary to use pip3.

(Even that knowledge might not resolve the conflict of potentially having 2 implementations of Python3 on the system. And I acknowledge that @paddyg has said the same thing... )

Have you tried using the library on a standard Raspbian system with only the default Python3 interpreter which comes pre-installed?

djdan_23
Posts: 19
Joined: Thu Aug 17, 2017 1:42 am

Re: No module named 'smbus' on Python3.6.2

Sun Sep 10, 2017 3:05 pm

As reply at "Sun Sep 10, 2017 1:13 pm" both "pip install smbus" and "pip3 install smbus" give the same error:
Could not find a version that satisfies the requirement smbus (from versions: )
No matching distribution found for smbus
Here's the pip version installed:
# pip --version
# pip 9.0.1 from /usr/lib/python2.7/dist-packages (python2.7)

# pip3 --version
# pip 9.0.1 from /usr/local/lib/python3.6/sites-packages
# (python3.5)
I tried "python 3.0 --version" and 3.1-3.2-3.3-3.4 and it command not found
but 3.5 wrote: Python3.5.3
So i tried python3.5 chronodot.py and still the same : ImportError: No module named 'smbus2'
My scrip is one line: import smbus2 as smbus

new scrip 2lines:
import smbus as smbus
import smbus2 as smbus
and with "python3.5 chronodot.py" it pass over smbus as smbus but failed with smbus2.
and with "python3.6 chronodot.py" it failed with smbus

User avatar
rpdom
Posts: 12590
Joined: Sun May 06, 2012 5:17 am
Location: Essex, UK

Re: No module named 'smbus' on Python3.6.2

Sun Sep 10, 2017 3:43 pm

sudo pip3 install smbus2

djdan_23
Posts: 19
Joined: Thu Aug 17, 2017 1:42 am

Re: No module named 'smbus' on Python3.6.2

Sun Sep 10, 2017 4:05 pm

YOU'RE THE BEST.
It works properly now.

Question 1 : Is smbus2 better then smbus.
Question 2 : Must I keep smbus2 instead of smbus.

Thank you very much.

User avatar
paddyg
Posts: 2123
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: No module named 'smbus' on Python3.6.2

Sun Sep 10, 2017 5:20 pm

IMHO the python2v3 and pip2v3 ambiguity is an unasked for complication. At this stage (stretch) "python" and "pip" as symbolic links to python2.7 should have been removed so users have to type python2, python3, pip2 or pip3. At the next issue of debian (buster) python and pip should point to python3.x

It's now only 27 months until python2 is officially retired!
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

hippy
Posts: 3180
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: No module named 'smbus' on Python3.6.2

Sun Sep 10, 2017 5:41 pm

B.Goode wrote:
Sun Sep 10, 2017 2:26 pm
Even that knowledge might not resolve the conflict of potentially having 2 implementations of Python3 on the system.
After I had manually built and installed 3.6.0 under Jessie alongside the default 3.4 ( or whatever ) I ran into all sorts of problems when installing Python 3 packages and trying to run the AIY project.

Each Python 3 version saw different packages and things went horribly wrong. I suspect one might have to use the specific version of pip for it to use the correct path, different things seeing different defaults.

Never resolved the issue, moved on to something else, and am now on default Stretch installs.

User avatar
bensimmo
Posts: 2911
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: No module named 'smbus' on Python3.6.2

Sun Sep 10, 2017 8:11 pm

You should be able to use pip3.4 pip3.5 pip3.6 to tell it which version of python3 you want to install it too
so
pip3.6 install smbus
should do the job.
*

smbus is python3 compatible, smbus2 should no longer be needed.
I know as converted all my smbus2 i2c's back to smbus. (in raspbian at some point it wasn't and then changed, didn't notice when but sometime in jessie iirc, either than or smbus was broken on my setup ;-))


*smbus isn't on pypy iirc.
maybe you need to set some environment variables up.
Cannot help as I've never needed to do it.

Return to “Python”

Who is online

Users browsing this forum: Baidu [Spider], Paeryn and 20 guests