Page 1 of 1

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

Posted: Wednesday 18 July 2018 15:28
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'

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

Posted: Friday 20 July 2018 8:20
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.