How to debug python scripts in Python

CMD is a simple shell it only knows 2 types of commands: builtins and executables. Builtins are things like cd, ls, dir, mkdir etc. If cmd doesn’t recognize a builtin it treats the command as executable and it’s arguments if any are present.
So when you type in pcbdraw MIC28515_Voltage_Regulator_Module.kicad_pcb test.jpg it tries to find an executable named pcbdraw.exe on %PATH%. The reason it works is because pcbdraw package has configured an entry point which setuptools will generate an exe for. Essentially that exe just calls a python function main() in pcbdraw.py.

You can run where pcbdraw in cmd and it will tell you where exactly it found pcbdraw.exe.

To run it manually with a debugger or with another interpreter just run pcbdraw.py, it runs main() by default.

1 Like

Huh ok that’s going to save a lot of headache throughout my life thank.
So yeah that help but in order to properly start building tools and scripts for python I still need to understand how to include what I guess is the default python libraries used by kicad from “C:\Program Files\KiCad\lib\python2.7\site-packages” at execution from pycharm and assuming I want to use the latest python 3.9 (because why wouldn’t I…) would the fact that the libraries are written in python 2.7 not allow for that? is there a newer kicad library source for the newer python out there?

python 3.9 seems to work well for execution within eeschema (In the BOM executer)

And It’d be useful to know where kicad developers get concentrated updates about the development news and future directions?

Pycharm will automatically include them provided you use the kicad’s python. But you can’t generally speaking use those libraries with python3.9 as they are built for python2 using different toolchain from official windows python builds, which would make them incompatible even if they were python3.

Work is ongoing in that direction, v6 will likely ship with pyhon3 on all platforms.

There is kicad mailing list and gitlab org where you can keep track of announcements and issues.

Well that’s sad :frowning: I’ve started developing a kicad script that autobuild and sources components jsut from digikey for now) that:

  1. tries to guess according to component reference, value and foortprint the corresponding component of digikey usually optimizing for price because in 90% of cases an 0603 resistor is just an 0603 resistor

  2. auto fill other tabs (like description price, purchase link, distributor PN and other info) according to a single MFR_PN field or LINK just to automate millions of copy paste operation during the development of a PCB

and just go on from there try to automate the workflow with python as much as possible…

so according to what you say I should just drop it until the next kicad gets released?

I’d love to help with that anyways but I almost have no experience developing GUI apps with wx and currently mainly focus of python rather than C++

also for some reason KiCad folder is located both in Program Files and "Program Files(x86)
Is it possible to remove one of them?

You can do everything you mentioned using your own interpreter and completely ignore what kicad ships with. There is nothing in kicad’s shipped python libs that will help you anyway.

You are only forced to use kicad’s interpreter if you are writing footprint wizards, pcbnew action plugins or want to use pcbnew python API. At least that’s the case until Eeschema has it’s own API, at which point you will also have to use kicad’s interpreter for that.

So I would say you don’t have to drop it if you just want to develop a script for yourself or maybe publish it for others. Just instruct your users to install separate interpreter or package your own.

If you want to help with working on kicad project itself I would start by familiarizing yourself with wxwidgets, reading kicad code and starting by small bugfixes from gitlab issue tracker.

That must be 32bit version you had at some point. It’s safe to remove it.

Sure thing I’ve manages to develop a BOM generator along with digikey API to build a CSV BOM with every important component info from digikey according to only one field (for now you just need to fill in MFR_PN and that’s it it the future I’ll automatically “guess” according to designator value and footprint(if available) the proper digikey part ) but It was annoying to do so because the debug is hard to see and other stuff…

Anyways I’d love to develop stuff for kicad in pycharm with python 3.9 but unless I manage to find where or how to include the kicad interpreter I’m stuck for now…

BTW seen some nice brand new elements in new kicad nightly but couldn’t find any article about the update is it possible that the newer python 3+ was added to kicad?

This sounds something like KiCost. Did you look at that solution? It maybe along your way, or at least you can look for inspiration.

Kicad on linux has been using py3 since v5.1. For Win and Mac work on moving to python3 is under way, as I mentioned above.

well I’ve seen it and already somewhat done building mine but KiCost just a price updater for certain quantities as mine is an auto filler from seed ,more work editing that script than building a completely new one…

Sure thing I’ll just want for nightly version to stop randomally crashing as often and get back to scripting once the python 3 push is over looks like I’m going to have a hard fight with it other wise and I don’t have much time learning linux extensively to just create python script

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