(2017-06-06, 21:09)ablues10 Wrote: (2017-06-06, 20:35)el_Paraguayo Wrote: The libreelec forum suggests the append line should be:
Code:
sys.path.append('/storage/.kodi/addons/virtual.rpi-tools/lib')
Have you tried that?
ERROR: EXCEPTION Thrown (PythonToCppException) : -->Python callback/script returned the following error<--
- NOTE: IGNORING THIS CAN LEAD TO MEMORY LEAKS!
Error Type: <type 'exceptions.ImportError'>
Error Contents: dynamic module does not define init function (initGPIO)
Traceback (most recent call last):
File "/storage/.kodi/addons/script.relay/addon.py", line 7, in <module>
import RPi.GPIO as GPIO
ImportError: dynamic module does not define init function (initGPIO)
-->End of Python script error report<--
That was using the Code:
sys.path.append('/storage/.kodi/addons/virtual.rpi-tools/lib')
This error means that a compiled dynamic library cannot be initialized as a Python module. It looks as if the binary GPIO module (_GPIO.so) is either incorrectly compiled or for a wrong platform. Make sure that you have installed this module from the official LibreELEC repo via Kodi Addon Manager. This should guarantee that you have correct binary components installed.
And for Kodi module addons you don't need to manipulate sys.path. Just add the necessary module addon to the
requires section of your addon.xml and it will be added to sys.path of your addon automatically.
BTW, just out of curiosity I've installed RPi tools addon and imported it with no problems:
addon.xml (excerpt):
Code:
<requires>
<import addon="xbmc.python" version="2.19.0"/>
<import addon="virtual.rpi-tools" />
</requires>
main.py:
Code:
from pprint import pformat
import xbmc
import RPi.GPIO as GPIO
xbmc.log(pformat(dir(GPIO)), xbmc.LOGNOTICE)
Result:
Code:
23:33:49.107 T:1240986528 NOTICE: ['BCM',
'BOARD',
'BOTH',
'FALLING',
'HARD_PWM',
'HIGH',
'I2C',
'IN',
'LOW',
'OUT',
'PUD_DOWN',
'PUD_OFF',
'PUD_UP',
'PWM',
'RISING',
'RPI_INFO',
'RPI_REVISION',
'SERIAL',
'SPI',
'UNKNOWN',
'VERSION',
'__builtins__',
'__doc__',
'__file__',
'__name__',
'__package__',
'__path__',
'add_event_callback',
'add_event_detect',
'cleanup',
'event_detected',
'getmode',
'gpio_function',
'input',
'output',
'remove_event_detect',
'setmode',
'setup',
'setwarnings',
'wait_for_edge']