OK, I think I understand better the Windows + Python + Kicad problem.
First, when using Kicad’s private Python shell, you have to force the installation of the dependencies (like matplotlib) in Kicad’s private Python dir. By default, pip2 installs the modules into the system’s Python2.7 directory… Obvious, once you think about it ! The command line is described later.
Second point, and the most problematic, I finally discovered that the Python shell from the Windows Kicad distro is a very special beast, built with GCC.
The essential file _pcbnew.pyd , part of the Kicad Python distribution (more or less a windows DLL in disguise) is built with GCC, too. And probably Kicad itself.
The official Python shell and modules are build with Microsoft tools (VC++).
Tracing the errors confirms the binary incompatibility (ABI : Application Binary Interface).
Then, any official python module (VC++) that tries to load some binary .pyd files will not work in the Kicad python shell (GCC). And vice-versa.
Specifically : Kicad python relies on the file _pcbnew.pyd (compiled with GCC).
The plugin we are testing (pcbnew_diff.py) relies on matplotlib. matplotlib uses numpy. And numpy tries to load the multiarray module : multiarray.pyd (VC++ Binary file).
If i use the Kicad’s python shell, it fails on multiarray.pyd.
If I use the official python shell, it fails on _pcbnew.pyd.
Indeed, this doesn’t happen on Linux, where GCC rules, and where developers have only one main Python installation.
Bottom line : based on this first experience, I can safely predict that Python extensions/plugins, that rely directly or indirectly on .pyd files (like matplotlib), are guaranteed to fail on Windows, unless developers :
- provide specially compiled version of these Python modules. Modules have to be installed in Kicad’s private Python directory. The extension/plugin will only work within the Kicad Python installation.
switch the Windows port to Visual C++ (may be challenging!!). In this case, a private Python is not necessary (I guess…), .
If a private Python installation is still required for some reasons, installation of external modules will have to target the Kicad install dir :
pip2 install PACKAGE --target DIR --upgrade (tested it).
In my case, DIR was “C:\Program Files (x86)\KiCad\lib\python2.7\site-packages”
Comments are welcome.
My 2 python-cents !