Can you use custom modules in Kodi, or create them yourself?
#1
I'm currently creating a small video addon simply to improve my Python skills.

I wrote a script that uses the vimeo module supplied by vimeo itself to retrieve a list of videos. I then want to show this list of videos in the addon. Relatively simple.
However, I'm using the custom vimeo supplied by vimeo, and this module is not recognized by Kodi. Is there a way to add this module as a dependency? Can I add the module content to the addon folder or can I add the module to Kodi's own library somehow? Or am I forced to write a completely new module/am I unable to use the features of the vimeo module at al?
Reply
#2
I'll move this to addon development
Read/follow the forum rules.
For troubleshooting and bug reporting, read this first
Interested in seeing some YouTube videos about Kodi? Go here and subscribe
Reply
#3
as this doesn't really sound very reusable just stick it in resources/lib in your add-on and import it from there. as such any module can be packaged up but no reason to do that if it wont be used by several add-ons.
Reply
#4
(2017-11-26, 12:51)spiff Wrote: as this doesn't really sound very reusable just stick it in resources/lib in your add-on and import it from there. as such any module can be packaged up but no reason to do that if it wont be used by several add-ons.
You mean I should copy the vimeo module from my pthon directory into my resources.lib directory of the addon? Then import it from there? I'll give that a go.
Reply
#5
(2017-11-26, 12:51)spiff Wrote: as this doesn't really sound very reusable just stick it in resources/lib in your add-on and import it from there. as such any module can be packaged up but no reason to do that if it wont be used by several add-ons.
 OK, so I did the following things:

- I copied the module folder for PyVimeo from C:\Users\[user]\AppData\Local\Programs\Python\Python36\Lib\site-packages to the resources\lib folder in my addon
- I added __init__.py files to my resources and lib folder
- In my addon.py file I added the line: from resources.lib import PyVimeo as vimeo
- I still get the error: ImportError: No module named resources.lib

EDIT: Ok so it seems to be able to find it now, but I get the following error:

" File "C:\Users\Eve\AppData\Roaming\Kodi\addons\plugin.video.R4E\addon.py", line 19, in getVimeoVideos
                                                v = vimeo.VimeoClient(
                                            AttributeError: 'module' object has no attribute 'VimeoClient' "

When using the script outside of Kodi I do not get this error and it works just fine. Any idea why attributes are missing from the module after importing it into Kodi?
Reply
#6
kodi uses python 2.7, you cannot use python3 code.
Reply
#7
(2017-11-26, 13:43)spiff Wrote: kodi uses python 2.7, you cannot use python3 code.
OK so I'll have to import python 2.7 but then what? I have now installed the module PyVimeo into the Python 2.7 folder. Should I copy it into my addon folder from there?

I have copied the PyVimeo folder from C:\Python27\Lib\site-packages to the resources\lib folder in my addon folder
Now i get the error:

"ImportError: cannot import name PyVimeo"

I ran a script which used the PyVimeo functionality in powershell with Python 2.7 as the version and it worked correctly there.
Reply
#8
Technically, your question has nothing to do with Kodi. You should learn how Python import works in general. TL;DR: there's sys.path global list that holds a list of paths where Python runtime searches for modules/packages. Current working directory is automatically added to that list so in simple cases you can just drop a third-party module/package beside the module that uses it. Or put that third-party in a directory you like and add that directory to sys.path. Addon's /resourses/lib is just one of possible options.
Reply
#9
(2017-11-26, 16:43)Roman_V_M Wrote: Technically, your question has nothing to do with Kodi. You should learn how Python import works in general. TL;DR: there's sys.path global list that holds a list of paths where Python runtime searches for modules/packages. Current working directory is automatically added to that list so in simple cases you can just drop a third-party module/package beside the module that uses it. Or put that third-party in a directory you like and add that directory to sys.path. Addon's /resourses/lib is just one of possible options.
I knew all that but the only mistake I made was copying the wrong directory from the Python 2.7 site-packages folder. This was due to their naming convention where the proper folder used a different name. It all works now. Thanks for all the help Smile
Reply

Logout Mark Read Team Forum Stats Members Help
Can you use custom modules in Kodi, or create them yourself?0