KiCad Python development under Windows

I have written a few plugins for KiCad using a painful setup not much different from typing into IDLE. I would like to do a lot more sophisticated work, which requires a better setup.

I am looking for guidance setting-up a solid Python/KiCad development environment under Windows 10, preferably using Pycharm Professional or VSCode if necessary. Any articles or posts I’ve been able to find on the subject are pre KiCad 6.

1 Like

Just point your VSCode to python.exe inside kicad’s bin folder. It should do the rest easily. Similarly in pycharm/idea add a python environment by pointing to existing installation and select python in kicad’s folder.
I described this process with a few more details here: Getting started using Python Scripts - #8 by qu1ck
It’s for kicad 5 but same works for 6.

1 Like

Similarly for VSCode press Ctrl-P and run “Python select interpreter” command.

image

As you can see I have selected here python from nightly build of kicad but you can enter any path.
VSCode will then parse pcbnew module as it’s on pythonpath for that interpreter.

2 Likes

It had to be that simple…

Just got around to looking at this. BTW, the keyboard shortcut in VSCode is Ctrl+Shift+P. Also, it did not surface the KiCad interpreter, just other Python interpreters I have on the machine. I just pasted the path by hand in Settings. Will mess with it some more in the coming weeks. Not sure if I need to make VSCode aware of wxPython and other libraries. Will figure it out.

Thanks.

This has been super helpful but I am not sure it’s quite working or maybe I am expecting too much?

I have set up the interpreter which gives me autocomplete on pcbnew, awesome. But if I do the following:

board = pcbnew.GetBoard()
board.{ctrl+Space}

I get “No suggestions”, essentially it can complete pcbnew, but not any other classes from there which would be really handy.

Video of what I mean may be clearer:

pcbnew module is not strongly typed because it’s generated by swig.
Help out your IDE by explicitly specifying types:
board: pcbnew.BOARD = pcbnew.GetBoard()
or python2 style
board = pcbnew.GetBoard() # type: pcbnew.BOARD

2 Likes

What were you hoping to do with this syntactically wrong Python statement?

The . indicates what should follow the class instance is either an attribute which is an identifier, or a class method, like in the previous statement.

However { starts a dict literal, and what’s more, it should contain key-value pairs separated by a colon.

They mean physically press ctrl and space keys after the dot to invoke the intellisense suggestions.

2 Likes

Ahh so expecting a bit much then! I’ll give those suggestions a go. Thanks.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.