I’ve tried hard to install the modules reportlab and pcbnew in the same python environment (using Windows 7/64), but without luck. Anyone out there who got it working or who can give me a hint?
Reportlab can not be installed in KiCad’s on-board Python environment (tested with 5.1.2 and 5.1.3 nightly), because KiCad’s Python is a bit restricted and does not provide zlib (reportlab depends on pillow, and pillow depends on zlib). Disabling the zlib dependency does not help, because Python will not use the wheels anymore and try to re-compile the sources, what fails because no Python header files & library files are included in KiCad.
reportab can e installed in a stadard 2.7.15 Python environment, but not the pcbbew module from KiCad - I guess due to compatiility issues: The standard Python environment is built by Microsoft VC++, while KiCad uses mingw64-gcc.
This should not be an issue. My guess is that it simply is a question of environment variable setup. (I have no experience in this regard under windows)
Do you want reportlab to be available from within kicads python console, via action plugins or do you plan on using a standalone python script?
Thank you for your reply! The script using pcbnew & reportlab schould be used as standalone python script from console.
I found a solution now, its not elegant but its working: I use a local Python 2.7 installation to install reportlab etc., set PYTHONPATH to this (C:\Python27\Lib\site-packages) and start the Python interpreter in C:\Program Files\KiCad\bin.
This works for reportlab, but not for svglib: Svglib it has dependencies to lxml, and lxml depends on etree. etree.pyd installed in C:\Python27 will not be loaded from KiCad’s Python environment. I assume it has to be compiled using KiCad’s Python or something.
Thank you again!
You didn’t tell how this does not work. What you tried, what you expected, what happened? If you want to use a standalone script this option sounds the best, provided that you can use a standalone python environment. Therefore I would solve this problem. But I would use python3 - is there a reason to stick to python2? (See https://pythonclock.org/ .)
Yes, we are stuck in Python 2.7.15 on Windows, because this is bundled with KiCad. I don’t think that KiCad on Linux uses a newer version for this.
Maybe there is someone who can tell me how to use the pcbnew module in a standalone Python 2.7 environment under Windows? The _pcbnew submodule is not loaded here, maybe because it was compiled with another toolchain…
I’ve never used Python before KiCad, and I have to say that I appreciate it very much. Except these dependency/compatibility issues, that makes me a bit crazy.
Set PYTHONPATH to pick up pcbnew.py and PATH to pickup _pcbnew.pyd. I never could make it work though.
Install precompiled pillow wheel from https://www.lfd.uci.edu/~gohlke/pythonlibs/ . It’s tricky and requires renaming a file to *-any.whl instead of win_amd64.whl but it can be done. Pillow will likely be broken anyway but it should let you install the lib you need. If you don’t actually depend on pillow features this may be satisfactory.
Install development environment with kicad-winbuilder, install pillow and any other deps from there and then use that build.
Sorry for posting this in the wrong thread first…:
This does not work, because the standalone Python 2.7 environment will not load the _pcbnew.pyd module: Here comes the output using -v:
# [...]
import string # precompiled from C:\Python27\lib\string.pyc
import strop # builtin
import pcbnew # from C:\Program Files\KiCad\lib\python2.7\site-packages\pcbnew.py
# wrote C:\Program Files\KiCad\lib\python2.7\site-packages\pcbnew.pyc
Traceback (most recent call last):
File "release.py", line 10, in <module>
import project
File "C:\Users\..\project.py", line 14, in <module>
import pcbnew
File "C:\Program Files\KiCad\lib\python2.7\site-packages\pcbnew.py", line 38, in <module>
import _pcbnew
ImportError: DLL load failed: The specified module could not be found.
The error message is a bit wired, but _pcbnew.pyd is definately found: When I rename it I will get another error message:
[..]
Traceback (most recent call last):
File "release.py", line 10, in <module>
import project
File "C:\Users\..\project.py", line 14, in <module>
import pcbnew
File "C:\Program Files\KiCad\lib\python2.7\site-packages\pcbnew.py", line 38, in <module>
import _pcbnew
ImportError: No module named _pcbnew
Both Pythons are built for the same architecture, but using different compilers. Might this be the problem?
Yes it does. KiCad is on python 3 nearly everywhere except windows. And even windows will only be a matter of time. (It has to be as it is a very bad idea to install python 2 after it no longer gets security updates.)
In other words: Make sure you develop your tools with version 3 compatibility (make use of the future stuff) such that you can switch easily once python 3 for kicad is available for windows (Only one dependency is missing for this switch.)