Executing Python Script
#1
Hello,
I have to problems, according to use python scripts.

1.
I tried to call a python script via another. The code looks like this:
Code:
import xbmc

xbmc.executebuiltin('XBMC.RunScript(special://home/scripts/on.py')

when calling the script via console with sudo python test.py it gives me this error:
Code:
osmc@PI:~/.kodi/scripts$ sudo python test.py
Traceback (most recent call last):
  File "test.py", line 1, in <module>
    import xbmc
ImportError: No module named xbmc

How to fix this?

2.
The second script should be called by the Yatse-Remote-App for Android. The App can call all of the Kodi functions (http://kodi.wiki/view/List_of_built-in_functions)
The on.py looks like this:
Code:
import wiringpi as wiringpi
wiringpi.wiringPiSetupPhys()
wiringpi.pinMode(3, 1) # sets physical pin 3 to output
wiringpi.digitalWrite(3, 0)
exit()
I added the exit() after I tried to call it with the Yatse-Remote-App for Android, and got the error that the script wont terminate.
But the main Problem ist, when calling this script via console it works flawless. But it doesn't work when called by the App.
I just get this warnings in the log file
Code:
17:04:32 2249.907959 T:1794118640 WARNING: CPythonInvoker(8): Script invoked without an addon. Adding all addon modules installed to python path as fallback. This behaviour will be removed in future version.
17:04:32 2250.401611 T:1829245936 WARNING: CPythonInvoker(0, /usr/share/kodi/addons/script.module.osmcsetting.updates/service.py): the python script "/usr/share/kodi/addons/script.module.osmcsetting.updates/service.py" has left several classes in memory that we couldn't clean up. The classes include: N14PythonBindings31XBMCAddon_xbmc_Monitor_DirectorE,N9XBMCAddon7xbmcgui12ControlImageE,N9XBMCAddon7xbmcgui6WindowE

Thank you in advande!
Reply
#2
You can't import xbmc modules in a stand-alone script, only when they are run by Kodi itself.

For testing, use

Code:
kodi-send --action='RunScript("/path/to/script.py")'

Any errors generated will appear in the debug log (wiki).
|Banned add-ons (wiki)|Forum rules (wiki)|VPN policy (wiki)|First time user (wiki)|FAQs (wiki) Troubleshooting (wiki)|Add-ons (wiki)|Free content (wiki)|Debug Log (wiki)|

Kodi Blog Posts
Reply
#3
(2016-08-04, 17:13)DarrenHill Wrote: You can't import xbmc modules in a stand-alone script, only when they are run by Kodi itself.

For testing, use

Code:
kodi-send --action='RunScript("/path/to/script.py")'

Any errors generated will appear in the debug log (wiki).

Unfortunately this gives me an error.
ERROR: Keymapping error: no such action 'runscript(special://home/scripts/off.py' defined


A general question... Am I right in the beliving that Kodi can run a random python script if its called with "RunScript" ?
Reply
#4
It's designed for testing scripts using SSH or similar terminals, before they get packaged up into add-ons.
|Banned add-ons (wiki)|Forum rules (wiki)|VPN policy (wiki)|First time user (wiki)|FAQs (wiki) Troubleshooting (wiki)|Add-ons (wiki)|Free content (wiki)|Debug Log (wiki)|

Kodi Blog Posts
Reply
#5
Hm okay,
but it means, that I can still use it for my purpose.

I just tried another command (TakeScreenshot) with Yatse, that I can be sure the app works correct with kodi - this does work.
Now I just have no clue how to get the runscript working.
Reply
#6
Maybe there is also another way to do it.
My goal is to turn on and off a relais which is connected to the rpi to turn on an off things like my ambilight/speakers/...
Since I don't want these devices to be turned on all the time, the only way I see it to work with a relais. And the relais is of coruse connected to the gpios which I can turn on and off in a python script/bash/c++programm afaik.

I read about the runscript which can execute python scripts - so it seems to be the easyest way for me
Reply
#7
Push
Reply
#8
You could:
-Make your own addon and trigger your script from it.
-Search for an existing addon which triggers scripts.
-Customize the skin you are using adding a menu item/sub-item which triggers the script.
-Map a remote or keyboard button to trigger the script.
Reply

Logout Mark Read Team Forum Stats Members Help
Executing Python Script0