Page 1 of 1

[Solved] VsCode/Pycharm - Can not resolve UNO imports

Posted: Sat Sep 02, 2023 1:57 pm
by LukeBB
I am creating some bigger Python macros in Libre Office. They run nicely from LO and also from IDE (both VSCode, Pycharm). To run from IDE, I use IDE_utils. IDE is recognizing XSCRIPCINTEXT, uno and unohelper. But when I import some packages like e.g.

Code: Select all

import pyuno
from com.sun.star.beans import UnknownPropertyException
the package names are underlined with error "can not find import", "can not resolve import" etc. The code runs fine in IDE and LO, no problem. Just the IDE does not recognize the packages, it does not know, where are these placed. Of course, I have set the LO Python interpreter in IDE and also tried to add

Code: Select all

"python.autoComplete.extraPaths": [
        "/usr/lib/python3/dist-packages/"
    ],
to VSCode configuration. It did not help. I can live with that ;) but still I am sad that the package names are not recognized by IDE, which means it thinks we have an arror there and of course intellisense does not work for these packages :cry:

Re: VsCode/Pycharm - Can not resolve UNO imports

Posted: Sat Sep 02, 2023 2:42 pm
by karolus
AFAIK there is no need for import pyuno because uno does it anyway.

slightly off Topic:
may i suggest you to use »jupyter-notebook« for interactive development? there are also plugins for both vscode and pycharm to work directly with …ipynb files.
Also »ooouno« may be helpfull, it provides autocomplete into the »com.sun.star…« -namespace, see screenshot from interactive Jupyter-notebook-session:
com.sun.star_autocomplete.png
com.sun.star_autocomplete.png (68.22 KiB) Viewed 4605 times

Re: VsCode/Pycharm - Can not resolve UNO imports

Posted: Sun Sep 03, 2023 8:16 pm
by LukeBB
Thank you karolus, ooouno package solved most of it!

Re: VsCode/Pycharm - Can not resolve UNO imports

Posted: Sun Sep 03, 2023 9:15 pm
by karolus
LukeBB wrote: Sun Sep 03, 2023 8:16 pm Thank you karolus, ooouno package solved most of it!
After some test with this I'm not sure about, the AutoComplete is the result of pushing a huge|deep com/sun/star/…/… folder-tree into …SitePackages, but most of these Auto-Suggestions seems Nonsense? at all.

disclaimer: yes I'm aware of: only Structs, Enumerations and Classes[1] are importable, but not Services
[1] their Names starts with X