Search code examples
pythonpip

LibreOffice, Python, get-pip, pip imports ok but then? module is in LibreOffice sitelib folder


Related questions:

How update Libre Office Python on windows?

Pyuno on Python 3.6 installation issue

I have downloaded get-pip.py to my LibreOffice program folder, and used it to install pip. Using pip in that folder, I have installed pymodbus. pip list shows that pymodbus is installed for that version of python, in that folder. And pymodbus is there, in the site-packages folder.

But when I try to run a script ("from pymodbus.client.sync import ModbusTcpClient ") in APSO, I get this error:

<class 'ImportError'>: No module named 'pymodbus.client.sync' (or 'pymodbus.client.sync.ModbusTcpClient' is unknown)
  File "C:\Program Files (x86)\misc\LibreOffice\program\pythonscript.py", line 1057, in getScript
    mod = self.provCtx.getModuleByUrl( fileUri )
  File "C:\Program Files (x86)\misc\LibreOffice\program\pythonscript.py", line 494, in getModuleByUrl
    exec(code, entry.module.__dict__)
  File "C:\Program Files (x86)\misc\LibreOffice\share\Scripts\python\MyTestScript.py", line 8, in <module>
    from pymodbus.client.sync import ModbusTcpClient
  File "C:\Program Files (x86)\misc\LibreOffice\program\uno.py", line 425, in _uno_import
    raise uno_import_exc
  File "C:\Program Files (x86)\misc\LibreOffice\program\uno.py", line 346, in _uno_import
    return _builtin_import(name, *optargs, **kwargs)

pip list tells me that the only known site packages are distlib, filelock, pip, platformirs, pymodbus, setuptools, virtualenv, wheel.

This is Win7/64, LibreOffice 7.4 (python-core-3.8.14).

Not particularly related questions: pip installed module but python gives Import error Too many different Python versions on my system and causing problems

https://extensions.libreoffice.org/en/extensions/show/apso-alternative-script-organizer-for-python is installed and can be used: https://superuser.com/questions/1297120/use-a-python-function-as-formula-in-libreoffice-calc-cells

There is no other python installed (but there has been). I don't know why a package which is in sitelibs should show that error: I don't know if I've done anything wrong or different. Does it make any sense to anyone else?

I've used that same package and same statement in other installations of python 3.8: This is the first time I've done anything with LibreOffice.


Solution

  • It turns out that, due to breaking changes in version 3.0 of pymodbus, the documentation at https://pymodbus-n.readthedocs.io/en/latest/readme.html#summary (Docs » PyModbus - A Python Modbus Stack, Summary) is not actually correct.

    And, of course, my reference implementation using Anaconda somehow got out of sync: conda-forge claims that its pyModbus version is 3.2, but somehow it managed to give me 2.3 instead.

    So this is not a LibreOffice question at all, and should be closed.