Where does the python plugin handler get it's pythonpath?

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

Post Reply
User avatar
fubar
Posts: 14
Joined: Friday 19 January 2018 3:44
Target OS: Linux
Domoticz version: beta
Location: Sydney
Contact:

Where does the python plugin handler get it's pythonpath?

Post by fubar »

I'm mucking about with a python plugin for a mi mini wifi plug.
It relies on python-miio.

Code: Select all

pip3 install python-miio
installs everything in ~/.local/lib/python3.6/site-packages/
That's how it is supposed to work - it won't put things into the system python, so that needs to be on the domoticz python path to be found by my plugin?

I've tried copying the contents of my site-packages to the domoticz/plugins/myplugin folder, but it fails to load a dynamic library needed - the error message includes a path that seems to have come from somewhere - can anyone offer a clue as to how I might change one of the two copies of "/usr/lib/python3.6" into something more useful for my plugin please?
2018-07-18 23:18:54.962 Error: (Miio_plugin) failed to load 'plugin.py', Python Path used was '/home/rlazarus/domoticz/plugins/Miio_plugin/:/usr/lib/python36.zip:/usr/lib/python3.6:
/usr/lib/python3.6:/usr/lib/python3.6/lib-dynload'.
2018-07-18 23:18:54.962 Error: (rossmiio) Module Import failed, exception: 'ModuleNotFoundError'
2018-07-18 23:18:54.962 Error: (rossmiio) Module Import failed: ' Name: miio'
User avatar
Dnpwwo
Posts: 819
Joined: Sunday 23 March 2014 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

Re: Where does the python plugin handler get it's pythonpath?

Post by Dnpwwo »

The plugin framework expects python to have a path set correctly already.

To answer your question, the path shown in the import error message is the output from the Python function

Code: Select all

Py_GetPath()
which is explained here: https://docs.python.org/3/c-api/init.html#c.Py_GetPath but I'm not sure that is what you want to know.

The good news is that you can modify this path within the plugin.py itself by placing a statement like this prior to the import statement:

Code: Select all

import sys
sys.path.append('/usr/lib/python3/dist-packages')
where you specify the location of the library you want to add. Note that this statement is slightly different on Windows and Linux though.
The reasonable man adapts himself to the world; the unreasonable one persists to adapt the world to himself. Therefore all progress depends on the unreasonable man. George Bernard Shaw
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest