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

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
LukeBB
Posts: 30
Joined: Wed Oct 26, 2016 10:35 pm

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

Post 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:
Last edited by LukeBB on Sun Sep 03, 2023 8:16 pm, edited 1 time in total.
LibreOffice 7.5.5.2 on Linux Mint 21
User avatar
karolus
Volunteer
Posts: 1199
Joined: Sat Jul 02, 2011 9:47 am

Re: VsCode/Pycharm - Can not resolve UNO imports

Post 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 4057 times
AOO4, Libreoffice 6.1 on Rasbian OS (on ARM)
Libreoffice 7.4 on Debian 12 (Bookworm) (on RaspberryPI4)
Libreoffice 24.8… flatpak on Debian 12 (Bookworm) (on RaspberryPI4)
LukeBB
Posts: 30
Joined: Wed Oct 26, 2016 10:35 pm

Re: VsCode/Pycharm - Can not resolve UNO imports

Post by LukeBB »

Thank you karolus, ooouno package solved most of it!
LibreOffice 7.5.5.2 on Linux Mint 21
User avatar
karolus
Volunteer
Posts: 1199
Joined: Sat Jul 02, 2011 9:47 am

Re: VsCode/Pycharm - Can not resolve UNO imports

Post 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
AOO4, Libreoffice 6.1 on Rasbian OS (on ARM)
Libreoffice 7.4 on Debian 12 (Bookworm) (on RaspberryPI4)
Libreoffice 24.8… flatpak on Debian 12 (Bookworm) (on RaspberryPI4)
Post Reply