Importing Python Modules

Hi,

I’m trying to import a module I wrote myself in my other python macros, but I kept getting errors for unable to import the module.

<class ‘ModuleNotFoundError’>: No module named ‘useful_func’

I tried to put it under $HOME/.config/libreoffice/4/user/Scripts/python like this page said but failed. Then I tried the path /Scripts/python/pythonpath described in this page still failed.

Besides the question about how to get it right, my point here is that these two pages shows different paths (and both failed…). Is it me misunderstanding something or should it be clear for more?

Regards, Franklin

Please, we show the value of sys.path in your system

import sys

print(sys.path)

What operating system are you using? If on Linux, how did you install LibreOffice… is it a Snap or Flatpak package?

This will affect the path where your Python scripts reside.

You can copy and paste here the info in the Help - About dialog.

Well, I tried and realized that only macros in my user profile folder ($userprofile/Scripts/python) could import modules I wrote and put under Scripts/python/pythonpath. I was trying with macros in an ods file but failed. I think it makes sense. Just not very trivial in the help documents.

I suspect ‘Document Module import’ is what you are looking for