Pcbnew cannot be imported in python3.5

Hi everyone, I just started learning to customize my foorprint via python scripts. I got stuck on “import pcbnew” because it gave me the error “no module name pcbnew” all the time. I checked my Kicad folder and found all the py examples for script foorprint wizard, but there’s no file named “pcbnew.py”.
I’m wondering if it’s because I’m using python3.5 rather than python2.7 and how can I fix this problem. Should I download the pcbnew script from somewhere like Kicad Github (I searched a lot but didn’t find any really helpful solutions…)? Or should I reinstall my Kicad or python? My Kicad version is 5.0.
Thanks a lot!

Tell what’s your OS and how did you install KiCad.

My OS is Windows7 and I downloaded Kicad5.0 from Kicad website. My Kicad itself works fine. Thanks!

There is python 2.7 packaged with kicad (look for it in bin folder in installation directory), use that instead of standalone python.

Thanks! So I need to install py 2.7 right? Do I need to uninstall py3.5?

You don’t have to install or uninstall anything. KiCad already comes with python, that python is configured so that it will detect pcbnew.py (which also comes with KiCad) and you can use it right away.

1 Like

But I tried to run my script starts with “import pcbnew” and it gave me the error…

Like I said, you need to use python that comes with KiCad, not the one you have installed by yourself.
Go to where your kicad is installed, then go to bin and you will see python.exe there, run that one, it will be able to find pcbnew module.
If you still get an error that means you have one of old KiCad versions installed that had scripting disabled by accident, in that case download and install latest package.

2 Likes

Get it! Thanks a lot!

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