ImportError: No module named xbmc
#1
Question 
I'm trying using the xmbc library to my code on python, exactly y need the method xmbc.getCondVisibility('Player.HasMedia') to know that kodi is treaming a file.I write their imports but when I run the file, this say:
ImportError: No module named xbmc
The code:
python:
import os
import time
import signal
import sys
sys.path.append('/storage/.kodi/addons/virtual.rpi-tools/lib')
import subprocess
import socket
import xbmc
import xbmcgui

while True:
    if xbmc.getCondVisibility('Player.HasMedia'):
        setMovieScene()
        sleep(3)

the source:
https://forum.kodi.tv/showthread.php?tid=244430
http://kodi.wiki/view/List_of_boolean_conditions
If I edit line xbmc for kodi, I get this error:
python:

--import xbmc
--import xbmcgui
++ import kodi
ERROR: AttributeError: 'module' object has no attribute 'getCondVisibility'
I run this program in autoexec.py in userdata folder
Reply
#2
You have a typo: xmbc must be xbmc:
python:
if xbmc.getCondVisibility('Player.HasMedia'):
Reply
#3
(2017-12-27, 14:53)ultraman Wrote: You have a typo: xmbc must be xbmc:
python:
if xbmc.getCondVisibility('Player.HasMedia'):
 It isn`t the problem,
In the original code I write xbmc, the problem is the error when I write: import xbmc
¿How I can use Player.HasMedia in python code for execute via console?
Reply
#4
Well, with xbmc it works. But you can't import xbmc module running python script directly from console - it must be run from Kodi.
You can try
bash:
kodi-send -a "RunScript(/storage/.kodi/userdata/autoexec.py)"
Of course you can use other file not autoexec.py. What you need is probably service addon.
Reply
#5
(2017-12-27, 15:33)ultraman Wrote: Well, with xbmc it works. But you can't import xbmc module running python script directly from console - it must be run from Kodi.
You can try
bash:
kodi-send -a "RunScript(/storage/.kodi/userdata/autoexec.py)"
Of course you can use other file not autoexec.py. What you need is probably service addon.
 I don´t understant you,  I want that autoexec.py it to run automatically and be able to know that kodi is streaming video
Reply
#6
autoexec.py you posted works (I test it). Not sure if loop there is good idea that's why I propose to you service addon which runs in background.
Reply
#7
(2017-12-27, 16:13)ultraman Wrote: autoexec.py you posted works (I test it). Not sure if loop there is good idea that's why I propose to you service addon which runs in background.
 ok, thanks, I will do service addon: 
http://kodi.wiki/view/Add-on_development
http://kodi.wiki/view/Service_addons

I understand that it is not possible to do what I want with the autoexec.py, if someone who reads the publication knows how to do it, please write it
Reply
#8
You can't access xbmc* modules from outside Kodi. If you need to control Kodi state from an external application, you can use JSON RPC.
Reply

Logout Mark Read Team Forum Stats Members Help
ImportError: No module named xbmc0