Clarification on Python Load Path
#1
Hi,

Recently I've had users complaining of issues with an addon I develop, which I ended up tracking down to conflicts between the module included in the resources/lib directory and another module installed on their system as a xbmc library/script. Now these are usually conflicts with modules that I haven't specified in the addon.xml file, but it seems they're still included in the python module lookup path. Is that the correct behaviour? I would have thought that I should only get the modules that I've declared in my addon.xml included. What do others do about this to avoid conflicts, do they usually rename their bundled dependencies or ensure when they modify the python path that the folders they add are added at the start rather than the end?

Thanks,
Adam
Reply
#2
every addon that has
<extension point="xbmc.python.module" library="lib"/>
will be considered as something that can be imported.
so if you have such a module installed that has the same name as the one you included you will have issues.
it doesn't matter if you have it included it in addon.xml or not.

to avoid conflicts just use the module and add it as dependency or rename the one you have included.
also be careful naming .py files that could also have the same name as some existing module.
Maybe you don't have that particular module installed but other users might so be careful using same names or shipping modules.

you should not alter the python path.
the correct way to import libs should be like this
https://github.com/XBMC-Addons/script.ar...ult.py#L36
and not adding your resource path ("sys.path.append") as python lib as some add-ons do.
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
(2014-06-19, 15:09)Martijn Wrote: also be careful naming .py files that could also have the same name as some existing module.
Maybe you don't have that particular module installed but other users might so be careful using same names or shipping modules.

That sounds very brittle, as sometimes is very difficult to come up with unique names and there's still no guarantee it won't conflict.

(2014-06-19, 15:09)Martijn Wrote: you should not alter the python path.
the correct way to import libs should be like this
https://github.com/XBMC-Addons/script.ar...ult.py#L36
and not adding your resource path ("sys.path.append") as python lib as some add-ons do.

Could you expand on the reasoning behind this? It sounds like my issue would be solved if I use sys.path.insert(0, dir) as that would mean my libs would be resolved before anyone else's, no?
Reply

Logout Mark Read Team Forum Stats Members Help
Clarification on Python Load Path0