HOW-TO:Python Development in Visual Studio

From Official Kodi Wiki
Revision as of 16:21, 29 August 2022 by RogueScholar (talk | contribs) (RogueScholar moved page HOW-TO:DebugAndDevelopPythonScriptsWithVisualStudio to HOW-TO:Python Development in Visual Studio: Simplify and improve readability)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Getting Started

This guide is based on Visual Studio 2013, this guidance may be relevant for other versions but mileage may vary!

Setting up your Project

If you have existing code go to File -> New -> Project and select From Existing Python Code, otherwise select Python Application. these project templates are under Templates / Python Update the name and the location relevant to your choice.

From Existing Python Code

For the existing code option ensure all the files are added, if you miss some you can add them to the project later. On the next page select the Python version you are running against. On the final page ensure you are happy with your project file name and location and click on Finish.

Python Application


Project Setup

These are optional but make the experience better.

To enable better intellisense for Kodi components use Kodistubs. This can be downloaded @ and all you need to do is add the location you downloaded the files from to the Search Paths. Add the Kodi addons directory to the search paths for the addons you are referencing. An example would be <KODI Root>\portable_data\addons\script.common.plugin.cache\lib to allow intellisense to work for StorageServer

Read the Kodistubs documentation for more detailed instructions.

Note: Intellisense will not be fully active until the DB is created, Press <Ctrl+K, `> to see its progress.

Running your project

Once you have a project up and running you have the magic of Visual Studio and the python tools at your disposal, along with any other adding to visual studio you like.

Right click on you python file that is the starting point for the plugin and ensure it is set as the startup file. If it is already bolded you do not have to worry about this.

Debugging your project

Work in Progress: Currently the attach process does not seem to be picking correctly for the breakpoints.

To debug your project you need to add a reference to ptvsd to your script and the project to enable intellisense.

  • Install ptvsd via pip
pip install ptvsd 
  • Add the following lines to the top of your script. Remember to comment out or remove once completed.
import ptvsd
ptvsd.enable_attach(secret = 'mysecret')
  • Set the breakpoint in your script that you want to check.
  • Start KODI
  • Start your plugin.
  • In Visual Studio use Debug -> Attach to Process menu command, which opens the Attach to Process dialog. The first thing to do in it is to open the Transport combo box, and change selection to Python remote debugging
  • For the qualifier add tcp://mysecret@localhost/