WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Python 3 cant find RPi.GPIO  (Read 4826 times)

Offline johnwmcc

  • Newbie
  • *
  • Posts: 10
Python 3 cant find RPi.GPIO
« on: December 09, 2018, 04:50:24 PM »
After a lot of hassle, i've installed piCore 9.03 on an RPi Zero W, got it to reboot and run WiFi, SSH, a desktop, python3.6, and x11vnc.

I've got onboot.lst to run these of modules on startup.


I've hit a number of roadblocks, which use of Google has mostly (eventually) resolved. Unfortunately, most of the instructions I found for installing piCore on Pi Zero W are incomplete or even inconsistent, but eventually I figured things out and have got most of what I want to do to work.

But I'm stuck, and can't find an answer using Google. I can load python3.6 (using sudo - naughty, I know, but it won't run the IDLE IDE unless I do that). At the python prompt, I get the IDE to run using
>>> import idlelib.idle


I've also run in a terminal the commandtce-load -iw python-RPi.GPIO to install the GPIO module, and put that in onboot.lst too. And if I run it a second time, it tells me it's already loaded.

But python can't find it. A python program using import RPi.GPIO fails, and creates an error.

Using Midnight Commander to search the mounted filesystem can find no file corresponding to a file search pattern of *RPi.GPIO* except .tcz files in tce/optional, anywhere.

What can I do to get GPIO to work in python3?

Is my problem to do with running python with sudo? If so, how do I get IDLE to work without that?

Any help would be welcome. At the moment I'm completely stuck.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11178
Re: Python 3 cant find RPi.GPIO
« Reply #1 on: December 09, 2018, 05:02:48 PM »
Hi johnwmcc
According to:
http://tinycorelinux.net/9.x/armv6/tcz/python-RPi.GPIO.tcz.list
that extension contains:
Code: [Select]
usr/local/lib/python2.7/site-packages/RPi.GPIO-0.6.2-py2.7.egg-info
usr/local/lib/python2.7/site-packages/RPi/_GPIO.so
usr/local/lib/python2.7/site-packages/RPi/GPIO/__init__.py
usr/local/lib/python2.7/site-packages/RPi/__init__.py
Is it possible python3 doesn't know to look under  /usr/local/lib/python2.7/  ?

Offline johnwmcc

  • Newbie
  • *
  • Posts: 10
Re: Python 3 cant find RPi.GPIO
« Reply #2 on: December 10, 2018, 08:29:05 AM »
I can see that the python2.7 files are there, and also that python 3.6 isn't finding them.

But how do I fix that?

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11178
Re: Python 3 cant find RPi.GPIO
« Reply #3 on: December 10, 2018, 08:34:56 AM »
Hi johnwmcc
See if Google returns anything useful for  PYTHONPATH.

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14516
Re: Python 3 cant find RPi.GPIO
« Reply #4 on: December 10, 2018, 08:52:03 AM »
I believe that you will have to recompile gpio against python3.6

Offline johnwmcc

  • Newbie
  • *
  • Posts: 10
Re: Python 3 cant find RPi.GPIO
« Reply #5 on: December 10, 2018, 08:59:34 AM »
I'm afraid I don't know how to do that. Has no one else done it already?

Where would I find instructions for compiling it, please?

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11178
Re: Python 3 cant find RPi.GPIO
« Reply #6 on: December 10, 2018, 09:11:10 AM »
Hi johnwmcc
Is there a reason you need Python 3.6? The  python.tcz  extension is version 2.7 and should work with the GPIO extension.

Offline johnwmcc

  • Newbie
  • *
  • Posts: 10
Re: Python 3 cant find RPi.GPIO
« Reply #7 on: December 10, 2018, 09:38:59 AM »
With a friend, we've been working on a routine to control motors and all the code is for python 3.

It worked, more or less, on Raspbian, but there are long delays when interrupts stop feeding back from optical sensors on the motors while other background processes run, so the motors overran.

We wanted to get it working on piCore as there should be a lot less overhead and things going on in the background.

We have tried installing RPi.GPIO for python 3.6 with pip, but it fails with errors I don't understand and can't easily copy here, unfortunately.

The first attempt failed saying gcc was missing, so we installed gcc with
tce-load -iw gcc.tcz.

The next run failed with a different error - compiler couldn't find Python.h.

Do we need to install python3.6-dev.tcz or something like that?
... later

Tried that. Now complaining it can't find limits.h.

At this point, I'm afraid, we are inclined to put piCore in the 'too difficult' pile.

« Last Edit: December 10, 2018, 09:53:03 AM by johnwmcc »

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14516

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11178
Re: Python 3 cant find RPi.GPIO
« Reply #9 on: December 10, 2018, 09:49:48 AM »
Hi johnwmcc
You need  compiletc.tcz.  This will give you a proper toolchain for compiling. You probably need  python3.6-dev.tcz.  There is
a build script for  python-RPi.GPIO.tcz  that may be of some help located here:
http://tinycorelinux.net/8.x/armv6/tcz/src/python-RPi.GPIO/python-RPi.GPIO.build
You'll probably need to adjust some of the variable assignments such as  SRCNAM, WRKDIR, etc.

Offline johnwmcc

  • Newbie
  • *
  • Posts: 10
Re: Python 3 cant find RPi.GPIO
« Reply #10 on: December 10, 2018, 09:55:17 AM »
Thank you - both responses from Juanito and Rich crossed with my making an edit to my previous post, so I hadn't seen them.

We'll have to stop for the moment, but will resume when possible.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11178
Re: Python 3 cant find RPi.GPIO
« Reply #11 on: December 10, 2018, 10:05:56 AM »
Hi johnwmcc
... Tried that. Now complaining it can't find limits.h. ...
Installing  compiletc.tcz  will fix that.

Offline Juanito

  • Administrator
  • Hero Member
  • *****
  • Posts: 14516
Re: Python 3 cant find RPi.GPIO
« Reply #12 on: December 10, 2018, 11:07:24 PM »
python3.6-RPi.GPIO posted to piCore 9.x armv6/armv7 repos (not tested)
« Last Edit: December 10, 2018, 11:09:51 PM by Juanito »

Offline johnwmcc

  • Newbie
  • *
  • Posts: 10
Re: Python 3 cant find RPi.GPIO
« Reply #13 on: December 11, 2018, 04:07:37 PM »
Many thanks. That's solved that problem, and we can now run the motors.

But in the switch from running the ZeroW with a monitor, mouse and keyboard, to running it headless using VNC, the screen resolution for the VNC connection has dropped from the monitor resolution of full HD 1920 x 1080 to an unusably small 600 x 480 or maybe 800 x 600. When the monitor was still plugged in, VNC gave us full HD. Now it doesn't, now the monitor is no longer plugged in.

Google search has not found us a way to increase this - posts refer either to changing Windows screen resolution, or an option in VNC preferences which doesn't exist on the piCore version of the server or in the client connected to it.

There's also a reference to uncommenting an entry hdmi_force_hotplug=1 in a /boot/config.txt file, and the file (never mind the option) doesn't seem to exist on the piCore file system.

Any suggestions for where else to look? Can't find anything relevant in /etc/X11 or other plausible /etc files.

Both of us have limited linux knowledge, and very little specific to piCore.

Thanks again if anyone can help us with this (we hope) final hurdle!
« Last Edit: December 11, 2018, 04:17:09 PM by johnwmcc »

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11178
Re: Python 3 cant find RPi.GPIO
« Reply #14 on: December 11, 2018, 05:34:25 PM »
Hi johnwmcc
Quote
There's also a reference to uncommenting an entry hdmi_force_hotplug=1 in a /boot/config.txt file, and the file (never mind the option) doesn't seem to exist on the piCore file system.
If you do this:
Code: [Select]
sudo mount /dev/mmcblk0p1 /mnt/mmcblk0p1Is  config.txt  found when executing this:
Code: [Select]
ls /mnt/mmcblk0p1
Quote
Any suggestions for where else to look? Can't find anything relevant in /etc/X11 or other plausible /etc files.
Googling for this:
Code: [Select]
x11vnc resolution no monitorreturned a lot of results. A thread on the  archlinux  forum suggested that  tigervnc  might be easier to set up.