In my comment I mentioned two different possibilities to include additional python modules with a QGIS python plugin. Regarding how and where a plugin is installed, it is not comfortable or even possible to install python packages into the standard lib directory or another folder in the standard python path, because extra steps, like copying files or using pip in the commandline, are required.
The first possibility to use a python module without installing it, is to work with relativ imports. Because the plugin directory acts as a python package, additional modules can be imported with dot-syntax like import .additional_module
. The module itself can be stored in a subdirectory, with an __init__.py
or as a single module file in the plugins main folder.
The second possibility is to modify the python path through the sys module, like Josephs example shows. With sys.path.append
you add an arbitrary folder to your python path which enables the absolut import way with import additional_modul
. For a plugin, best practise would be a folder in the plugin directory, call it lib
or libraries
, again, see Josephs comment.
Because the qgis plugin folder is inside the user profile, it is save to create an additional folder under the profile path and expand the python path with that. That allows other plugins to use this module too. But you can't do that by the official download and extract installation of a plugin.