Using VS Code importing Python libs
#1
Hi there.
I am trying to use VS Code for Kodi addon development, just started. VS code tells me of course it cant find the python libs "import xbmc" etc., i know i cant execute where i develop, i code directly in the addons folder where kodi runs, but can i get "rid" of these messages and get the python libs into VS Code on my desktop?

Thanks for any advice.
Reply
#2
Take a look at Kodi Stubs:

https://github.com/romanvm/Kodistubs

I don't use it myself (I just ignore the VS Code warnings), but I believe installing these will get rid of the warnings (and probably give you the type ahead for calls too).
Reply
#3
(2024-03-15, 19:34)iceman20k Wrote: Hi there.
I am trying to use VS Code for Kodi addon development, just started. VS code tells me of course it cant find the python libs "import xbmc" etc., i know i cant execute where i develop, i code directly in the addons folder where kodi runs, but can i get "rid" of these messages and get the python libs into VS Code on my desktop?

Thanks for any advice.

  Setup a python "virtual environment" using venv.  I don't do it in VS Code.  I have python 3.8 installed on my system.  I run venv from a command prompt using Python 3.8 and have a folder tree with various subfolders per venv.  But I am also lazy and sometimes will just tell VS code to use my python 3.8 environment.  Either way I use pip to get kodi stubs from pypi for either a venv or my main python 3.8.

Then in vs code you can set your python to your venv or python 3.8 and import xbmc, xbmcgui etc.  Kodi stubs has full docstrings that vs code will show.

Also suggest creating a .env file with a PYTHONPATH variable set for all the script.modules needed (you can run your script in Kodi with debugging and Kodi will log the sys.path for your addon which you can copy into your .env).

As far as debugging, I have to admit I have not figured out how to correctly set up remote debugging for an addon running within a local Kodi process in Windows.  When my addon starts it pauses waiting for a connection but I'm never able to get the debugger to actually connect and it times out.

I also use github desktop.  Set up a folder script.myscript that has .gitignore, .vscode, .env etc and a subfolder script.myscript with the actual code.  VS code can do git, but I haven't explored that as using github desktop seems more powerful.

scott s.
.
Reply
#4
Wow, thank you both, an easy use of "pip install Kodistubs" has "eaten up" all these noisy error messages. Thank you! (I already had a venv up...)
I just didn't thought installing Kodistubs would solve this and "just" help for autocompletion and the like. That brings me to a thought, i have read https://kodi.wiki/view/Development_Tools before asking here, but there is not hint that it also fully eliminates these library erros. At least for me, that would have been a good hint. Operators of the page may want to add this hint. Just a thought, thanks again.
Reply

Logout Mark Read Team Forum Stats Members Help
Using VS Code importing Python libs0