VS Code and Python Macros in LibreOffice

I was able to use VS Code as an Editor for Python Macros in LibreOffice Calc. But VS Code doesn’t really integrate as an IDE in that situation, due to the two environments not connecting or merging.

My basic question is How to get VS Code to recognize / integrate into the Python environment that LibreOffice expects to see, and not throw up PyLance errors.

In order to get Python Macros working in LibreOffice, one has to install and figure out one or more extensions related to the pyuno bridge between the UNO objects that the LibreOffice API provides and the Python interpreter being used.

I’m currently using MX-Linux 23 (Debian Bookworm based), Python 3.11.2 (and experimentally 3.13 which I compiled myself ) and LibreOffice 25.2 [previously I had LibreOffice 7.4 running, but upgraded] apologies to Windows users - you’ll have to work that out ..

LibreOffice appears to start up its own Python environment using scripts in the /usr/lib/libreoffice/program directory (in my case /opt/libreoffice25.2/program/) called
pythonloader.py pythonscript.py and perhaps uno.py and unohelper.py

These provide an object called XSCRIPTCONTEXT to the running python interpreter - which in my experience is missing in the startup under VS Code.

I simply don’t know how to get VS Code to initialize this object and consequently stop throwing PyLance errors. I’ve also never used PyLance before and don’t know how it ties into the VS Code ecosystem.

I was working on my 2025 tax return using LibtreOffice and lacked time to go further in my digging, learning and experimenting - but got a macro going that helped me finish on time anyway. As mentioned earlier - VS code did work fine as a plug-in Editor - just useless as an IDE.

You would need to either point the Python extension at the Python installation that LibreOffice is using or set your PYTHONPATH to point to where LibreOffice is keeping all of its Python code.

Otherwise you can open an issue at GitHub · Where software is built .

It’s the type checker and code completion tool that ships with the Python extension for VS Code by default.

Thank you, but I don’t know how to get the VS code Python extension ms-python.python to point to /opt/libreoffice25.2/program/python (which turns out to be a shell script invoking python.bin in that directory, and is python 3.10.16 the directories and files are all owned by root - so I tried manually adding a .vscode directory owned by myself and an environment file .venv owned by myself also.
I did that because of 'unable to create … ’ error messages in regard to using the VS code command palette to choose a Python interpreter and create an environment for it.

Setting the PYTHONPATH=/opt/libreoffice25.2/program inside the actual python macro script doesn’t seem to do it either. I was able to tweak the attached terminal to invoke 3.10.16 – but it doesn’t find the module to create virtual environments !! python3.10.16 -m venv

very slow progress here

Apparently I need to be looking at GitHub - Amourspirit/live-libreoffice-python

Not sure what deep waters that will lead me into . . .