WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Python 3.6 is unable to find Python's smbus module  (Read 3724 times)

Offline gatorback

  • Newbie
  • *
  • Posts: 17
Python 3.6 is unable to find Python's smbus module
« on: February 27, 2020, 10:24:19 AM »
smbus is required for a relayboard and is a hurdle to overcome before trying the suggestion to create an python extension.


From the python console smbus is not found with (sudo) Python3.6 and returns:
 
Code: [Select]
>>>import smbus
ModuleNotFoundError: No module named 'smbus'

python 2.7 on the other hand loads smbus.

>>> import smbus
>>>

Why is Python 3.6 not successful finding smbus and what will remedy the issue?  What diagnostics can be performed to determine root-cause?
« Last Edit: February 27, 2020, 10:31:06 AM by gatorback »
Raspberry Pi Zero W

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14849
Re: Python 3.6 is unable to find Python's smbus module
« Reply #1 on: February 27, 2020, 10:33:30 AM »
Is it smbus2?

Offline gatorback

  • Newbie
  • *
  • Posts: 17
Re: Python 3.6 is unable to find Python's smbus module
« Reply #2 on: February 27, 2020, 10:42:40 AM »
Good question!  How can one determine version of the smbus extension?

/mnt/mmcblk0p2/tce/optional/py-smbus.tcz

was downloaded from:

wget http://tinycorelinux.net/7.x/armv6/tcz/py-smbus.tcz

$ md5sum /mnt/mmcblk0p2/tce/optional/py-smbus.tcz
0e8df4164f50c957b7281fd018472e8d  /mnt/mmcblk0p2/tce/optional/py-smbus.tcz

« Last Edit: February 27, 2020, 11:02:42 AM by gatorback »
Raspberry Pi Zero W

Offline gatorback

  • Newbie
  • *
  • Posts: 17
Re: Python 3.6 is unable to find Python's smbus module
« Reply #3 on: February 27, 2020, 10:44:23 AM »
Does a version3 of py-smbus exist?

tc@box:~/megaio-rpi/python/megaio$ wget http://tinycorelinux.net/9.x/armv6/tcz/py-smbus.tcz
Connecting to tinycorelinux.net (89.22.99.37:80)
wget: server returned error: HTTP/1.1 404 Not Found
tc@box:~/megaio-rpi/python/megaio$ wget http://tinycorelinux.net/8.x/armv6/tcz/py-smbus.tcz
Connecting to tinycorelinux.net (89.22.99.37:80)
wget: server returned error: HTTP/1.1 404 Not Found
« Last Edit: February 27, 2020, 11:02:15 AM by gatorback »
Raspberry Pi Zero W

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14849
Re: Python 3.6 is unable to find Python's smbus module
« Reply #4 on: February 27, 2020, 11:05:55 AM »
if you look at:
http://tinycorelinux.net/7.x/armv6/tcz/py-smbus.tcz.info
http://tinycorelinux.net/7.x/armv6/tcz/py-smbus.tcz.list

..you can see the details.

What I meant was that the python package available from pip for python3.6 might be called smbus2

To compile it I guess you need:

https://files.pythonhosted.org/packages/6a/06/80a6928e5cbfd40c77c08e06ae9975c2a50109586ce66435bd8166ce6bb3/smbus2-0.3.0.tar.gz

Offline gatorback

  • Newbie
  • *
  • Posts: 17
Re: Python 3.6 is unable to find Python's smbus module
« Reply #5 on: February 27, 2020, 11:19:54 AM »
Thank you for the links and orientation: is the compile process the same as your recommendation in your other posting?:

http://forum.tinycorelinux.net/index.php/topic,23561.0.html

Have you had success in the past compiling 2.X source code with 3.X tools?  My intuition tells me this may not be a simple "crank the handle" exercise.  Again, your experience is appreciated.  If successful, I would be happy to submit the results for the library for other users to enjoy
« Last Edit: February 27, 2020, 11:25:49 AM by gatorback »
Raspberry Pi Zero W

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11694
Re: Python 3.6 is unable to find Python's smbus module
« Reply #6 on: February 27, 2020, 11:26:05 AM »
Hi gatorback
... If successful, I would be happy to submit the results for the library for other users to enjoy
Instructions for submitting extensions can be found here:
http://wiki.tinycorelinux.net/wiki:creating_extensions#submitting

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14849
Re: Python 3.6 is unable to find Python's smbus module
« Reply #7 on: February 27, 2020, 11:28:07 AM »
Most python source code seems to compile equally well with python2.x or python3.x

From a quick look at the smbus2 source, it looks like the same instructions would work - which version of piCore are you using?

Offline gatorback

  • Newbie
  • *
  • Posts: 17
Re: Python 3.6 is unable to find Python's smbus module
« Reply #8 on: February 27, 2020, 11:35:58 AM »
PiCore 9.03.  Good to hear that your intuition indicates an optimistic forecast.  README.rst indicates a "pure python" implementation:

Quote
smbus2 is (yet another) pure Pythob implementation of the `python-smbus <http://www.lm-sensors.org/browser/i2c-tools/trunk/py-smbus/>`_ package.

This leads me to wonder if this provides any assurance that compiling with Python 3.X will be successful.
Raspberry Pi Zero W

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14849
Re: Python 3.6 is unable to find Python's smbus module
« Reply #9 on: February 27, 2020, 11:46:36 AM »
This leads me to wonder if this provides any assurance that compiling with Python 3.X will be successful.

It only takes a couple of minutes to try and see  :)

Offline gatorback

  • Newbie
  • *
  • Posts: 17
Re: Python 3.6 is unable to find Python's smbus module
« Reply #10 on: February 27, 2020, 01:45:55 PM »
UPDATE:
I am excited at the prospect of creating a .tcz file: here is the log!  After the smbus.tcz file was created: I have configure /tce/onboot.lst to load smbus.tcz at boot time.   The newly complied extension is saved to /tce/optional/: changes were backed-up with: filetool.sh -b

ROADBLOCK:
The new smbus.tcz loaded, however smbus did not import into python3.6 or 2.7:

Code: [Select]
tc@box:~$ cd /mnt/mmcblk0p2/tce/optional/
tc@box:/mnt/mmcblk0p2/tce/optional$ md5sum -c py-smbus3.tcz.md5.txt
py-smbus3.tcz: OK
tc@box:/mnt/mmcblk0p2/tce/optional$ md5sum py-smbus3.tcz
1427ef7aa496489aea6e596bc343f053  py-smbus3.tcz
tc@box:/mnt/mmcblk0p2/tce/optional$ md5sum py-smbus.tcz
1427ef7aa496489aea6e596bc343f053  py-smbus.tcz
tc@box:/mnt/mmcblk0p2/tce/optional$ tce-load -i py-smbus.tcz
py-smbus.tcz: OK
tc@box:/mnt/mmcblk0p2/tce/optional$ tce-load -i py-smbus.tcz
py-smbus is already installed!
tc@box:/mnt/mmcblk0p2/tce/optional$ sudo python3.6
Python 3.6.0 (default, Dec 23 2016, 19:26:34)
[GCC 6.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import smbus
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'smbus'
>>>

Did I miss a step somewhere?  What tests can be done to determine why module is not found?
« Last Edit: February 27, 2020, 01:52:42 PM by gatorback »
Raspberry Pi Zero W

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14849
Re: Python 3.6 is unable to find Python's smbus module
« Reply #11 on: February 28, 2020, 01:21:11 AM »
It should look like this, no:
Code: [Select]
$ tce-load -i py3.6-smbus2.tcz
py3.6-smbus2.tcz: OK
$ python3.6
Python 3.6.9 (default, Dec 11 2019, 17:44:28)
[GCC 9.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import smbus2
>>>