How to add external python package
#1
I'm developing an add-on that uses an Enum type that is not built-in Kodi Python. Enum is a new type (officially blessed by Python) and therefore is not a single .py file. Normally I would install the package into the current version of Python. I need to make Enums available to all my source code modules.

I've established a resource/lib directory for all my additional modules and referenced it in my addon.xml file. I read that I should copy the external package files to my lib directory and that would make the Enum type available for import in my source files. It hasn't worked and I get an error stating that it cannot find Enum.

Does anyone know how to resolve this issue?

Sent from my Galaxy Tab 2
Reply
#2
enum was introduced in python 3.4: https://www.python.org/dev/peps/pep-0435/
kodi uses python 2.7
Reply
#3
That's true but it was also back ported to 2.7.
I've got it working on my version of Python2.7 running on my PC.

Sent from my Galaxy Tab 2
Reply
#4
a link to your addon might make it easier for us to spot what's going wrong ;-)
Do not PM or e-mail Team-Kodi members directly asking for support.
Always read the Forum rules, Kodi online-manual, FAQ, Help and Search the forum before posting.
Reply
#5
The method is the same as for Python in general: you need to add a path to your module/package to sys.path list. Normally, for Kodi addons you need to retrieve a base path via Addon().getAddonInfo('path').decode('utf-8') and then to create an absolute path to your module/package directory with os.path.join. But this question is posted in PVR section so I'm a bit confused about what you are trying to build.
Reply
#6
The add-on I'm writing works with pvr live TV.
I'm dealing with a python package of modules I want to reference, not fonts.
I've created an extension point that points to the directory that contains the enum package (the parent package is named lib) and placed an "import enum" statement in the parent package's __init__.py file. The idea was to create the "enum" name in the parent package's namespace that would be found when other modules import enum. Unfortunately I haven't been able to get it to work yet.

Sent from my Galaxy Tab 2
Reply
#7
(2017-11-20, 17:42)jmooremcc Wrote: The add-on I'm writing works with pvr live TV.
I'm dealing with a python package of modules I want to reference, not fonts.
I've created an extension point that points to the directory that contains the enum package (the parent package is named lib) and placed an "import enum" statement in the parent package's __init__.py file. The idea was to create the "enum" name in the parent package's namespace that would be found when other modules import enum. Unfortunately I haven't been able to get it to work yet.

Sent from my Galaxy Tab 2
As I said, you need to add a directory containing your package to sys.path list. This is a standard Python way to make modules/packages available for import. If xbmcaddon.Addon class is not available (I don't know how it is done in PVR), then you can use os.path.dirname(os.path.abspath(__file__)) to obtain a base path as it is done in regular Python.
Alternative way is to create a separate script.module.enum addon and reference it in your addon.xml as a dependency.
Reply
#8
Problem Solved:
I came across an obscure article (Roman was a contributor) that suggested wrapping the library in a script module: https://forum.kodi.tv/showthread.php?tid=251555

The article had a link to a working example which helped me figure out what to do: https://github.com/xbmc/repo-scripts/tre...e.httplib2

I created a script module that contained the two enum package directories from my Python2.7 installation. I then imported the script module into my add-on with the result being no more "can't find Enum module" errors.

Thanks to all for your help.

Sent from my Galaxy Tab 2
Reply

Logout Mark Read Team Forum Stats Members Help
How to add external python package0