Install the v5.99 python modules?

I run KiCad v5.99 built locally from the git repo. I am trying to figure out how to install the corresponding Python libraries as have old v5.1 version for the Ubuntu package. I can’t see to figure out what make target will do that. Thanks!

Details:

This is the v5.1 version that comes from the Ubuntu package:
pdp7@x1:~/dev/kicad/kicad/build/debug$ find /usr/lib |grep -i pcbnew
/usr/lib/python3/dist-packages/pcbnew.py
/usr/lib/python3/dist-packages/_pcbnew.so
pdp7@x1:~/dev/kicad/kicad/build/debug$ python3
Python 3.8.5 (default, Jul 28 2020, 12:59:40) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pcbnew
>>> print(pcbnew)
<module 'pcbnew' from '/usr/lib/python3/dist-packages/pcbnew.py'>
>>> 

pdp7@x1:~/dev/kicad/kicad/build/debug$ dpkg -L kicad |grep python
/usr/lib/python3
/usr/lib/python3/dist-packages
/usr/lib/python3/dist-packages/_pcbnew.so
/usr/lib/python3/dist-packages/pcbnew.py
pdp7@x1:~/dev/kicad/kicad/build/debug$ dpkg -l kicad
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name           Version                                     Architecture Description
+++-==============-===========================================-============-============================================
ii  kicad          5.1.6-202005120822+c6e7f7d~86~ubuntu19.10.1 amd64        Electronic schematic and PCB design software

Here is the v5.99 install:

pdp7@x1:~/dev/kicad/kicad/build/debug$ which kicad
/usr/local/bin/kicad

Here is the v5.99 build dir:

pdp7@x1:~/dev/kicad/kicad/build/debug$ find |grep py$
./pcbnew/pcbnew.py

I tried:

$ export PYTHONPATH=$HOME/dev/kicad/kicad/build/debug/pcbnew

$ ls $PYTHONPATH 
altium2kicadpcb_plugin  connectivity         docstrings  pcad2kicadpcb_plugin  pcbnew.py   pcbnew_wrap.cxx  router
CMakeFiles              CTestTestfile.cmake  github      pcbnew                pcbnew.pyc  plugins          specctra_import_export
cmake_install.cmake     dialogs              Makefile    _pcbnew.kiface        _pcbnew.so  __pycache__      swig

But I failed to import pcbnew:

$ python3 
Python 3.8.5 (default, Jul 28 2020, 12:59:40) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pcbnew
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pdp7/dev/kicad/kicad/build/debug/pcbnew/pcbnew.py", line 38, in <module>
    import _pcbnew
ImportError: dynamic module does not define module export function (PyInit__pcbnew)

I have not seen that error before. It works for me with Python 3.7.3. Do you have KICAD_SCRIPTING_PYTHON3=ON in your CMakeCache.txt?

$ cat test.py
#!/usr/bin/env python3

import pcbnew

print(pcbnew.GetBuildVersion())
$ PYTHONPATH=$HOME/work/kicad/build/debug/pcbnew python3 test.py
(5.99.0-8218-g0234b7278a)
1 Like

Ah! Looks like I have it off:


//Build for Python 3 instead of 2 (default OFF).
KICAD_SCRIPTING_PYTHON3:BOOL=OFF              

//Build wxPython implementation for wx interface building in Python
// and py.shell (default ON).
KICAD_SCRIPTING_WXPYTHON:BOOL=ON

//Use new wxPython binding (default OFF).
KICAD_SCRIPTING_WXPYTHON_PHOENIX:BOOL=OFF

Turning that on should do the trick. From a quick search, it looks like that error is typical of building for Python 2 and running on Python 3

1 Like

I have run into this error now:

pdp7@x1:~/dev/kicad/kicad/build/debug$ cmake -DKICAD_SCRIPTING_PYTHON3=ON -DCMAKE_BUILD_TYPE=Debug  -DCMAKE_PREFIX_PATH=/usr/local  -DCMAKE_INSTALL_PREFIX=/usr/local  -DDEFAULT_INSTALL_PATH=/usr/local -DKICAD_CONFIG_DIR=kicad-master ../../
-- KiCad install dir: </usr/local>
-- Enabling warning -Wsuggest-override
-- Enabling warning -Wduplicated-branches
-- Enabling warning -Wduplicated-cond
-- Enabling error for -Wvla
-- Enabling warning -Wimplicit-fallthrough
-- Enabling error for -Wreturn-type
-- Enabling warning -Wshadow
-- Enabling warning -Wsign-compare
-- Enabling warning -Wmissing-field-initializers
-- Enabling warning -Wempty-body
-- Enabling warning -Wreorder
-- Disabling warning -Wpsabi
-- Check for installed GLEW -- found
-- Check for installed ZLIB -- found
-- Could NOT find PythonInterp: Found unsuitable version "2.7.18", but required is at least "3.3" (found /usr/bin/python2)
-- Check for installed Python Interpreter -- not found
CMake Error at CMakeModules/CheckFindPackageResult.cmake:6 (message):
  Python Interpreter was not found - it is required to build Kicad
Call Stack (most recent call first):
  CMakeLists.txt:751 (check_find_package_result)


-- Configuring incomplete, errors occurred!
See also "/home/pdp7/dev/kicad/kicad/build/debug/CMakeFiles/CMakeOutput.log".
See also "/home/pdp7/dev/kicad/kicad/build/debug/CMakeFiles/CMakeError.log".

Looks like this might be a problem:


//Python module install path.
PYTHON_DEST:PATH=lib/python2.7/dist-packages

//Path to a program.
PYTHON_EXECUTABLE:FILEPATH=/usr/bin/python2

//Path to a file.
PYTHON_INCLUDE_DIR:PATH=/usr/include/python2.7

//Path to a library.
PYTHON_LIBRARY:FILEPATH=/usr/lib/x86_64-linux-gnu/libpython2.7.so

@craftyjon is there a way for me to tell it to use Python 3?

I tried this:

pdp7@x1:~/dev/kicad/kicad/build/debug$ cmake -DPYTHON_INCLUDE_DIR=/usr/lib/python3.8 -DKICAD_SCRIPTING_WXPYTHON=ON -DKICAD_SCRIPTING_PYTHON3=ON -DCMAKE_BUILD_TYPE=Debug  -DCMAKE_PREFIX_PATH=/usr/local  -DCMAKE_INSTALL_PREFIX=/usr/local  -DDEFAULT_INSTALL_PATH=/usr/local -DKICAD_CONFIG_DIR=kicad-master ../../
-- KiCad install dir: </usr/local>
-- Enabling warning -Wsuggest-override
-- Enabling warning -Wduplicated-branches
-- Enabling warning -Wduplicated-cond
-- Enabling error for -Wvla
-- Enabling warning -Wimplicit-fallthrough
-- Enabling error for -Wreturn-type
-- Enabling warning -Wshadow
-- Enabling warning -Wsign-compare
-- Enabling warning -Wmissing-field-initializers
-- Enabling warning -Wempty-body
-- Enabling warning -Wreorder
-- Disabling warning -Wpsabi
-- Check for installed GLEW -- found
-- Check for installed ZLIB -- found
-- Could NOT find PythonInterp: Found unsuitable version "2.7.18", but required is at least "3.3" (found /usr/bin/python2)
-- Check for installed Python Interpreter -- not found
CMake Error at CMakeModules/CheckFindPackageResult.cmake:6 (message):
  Python Interpreter was not found - it is required to build Kicad
Call Stack (most recent call first):
  CMakeLists.txt:751 (check_find_package_result)

It is safer to make a clean configure, meaning you specify to enable python3 and phoenix at the first configure.

1 Like

Yeah, it is probably something cached by CMake already. I’m not sure the details of how the python finder works, but probably it has set a number of variables for Python2 already.

1 Like

Thanks @nickoe and @craftyjon. I deleted build and recreated but now am running into:

pdp7@x1:~/dev/kicad/kicad$ rm -rf build/
pdp7@x1:~/dev/kicad/kicad$ mkdir -p build/release
pdp7@x1:~/dev/kicad/kicad$ mkdir build/debug               # Optional for debug build.
(reverse-i-search)`c': ^C ..
pdp7@x1:~/dev/kicad/kicad$ cd deb
bash: cd: deb: No such file or directory
pdp7@x1:~/dev/kicad/kicad$ cd debu^C
pdp7@x1:~/dev/kicad/kicad$ cd build/debug/
pdp7@x1:~/dev/kicad/kicad/build/debug$ cmake -DKICAD_SCRIPTING_PYTHON3=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_PREFIX_PATH=/usr/local -DCMAKE_INSTALL_PREFIX=/usr/local -DDEFAULT_INSTALL_PATH=/usr/local -DKICAD_CONFIG_DIR=kicad-master ../../
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- KiCad install dir: </usr/local>
-- Looking for malloc.h
-- Looking for malloc.h - found
-- Looking for iso646.h
-- Looking for iso646.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for strcasecmp
-- Looking for strcasecmp - found
-- Looking for strncasecmp
-- Looking for strncasecmp - found
-- Looking for strtok_r
-- Looking for strtok_r - found
-- Looking for malloc
-- Looking for malloc - found
-- Looking for math.h
-- Looking for math.h - found
-- Looking for C++ include cmath
-- Looking for C++ include cmath - found
-- Looking for asinh
-- Looking for asinh - found
-- Looking for acosh
-- Looking for acosh - found
-- Looking for atanh
-- Looking for atanh - found
-- Performing Test HAVE_CMATH_ISINF
-- Performing Test HAVE_CMATH_ISINF - Success
-- Looking for clock_gettime in rt
-- Looking for clock_gettime in rt - found
-- Looking for gettimeofday
-- Looking for gettimeofday - found
-- Looking for getc_unlocked
-- Looking for getc_unlocked - found
-- Performing Test COMPILER_SUPPORTS_WSUGGEST_OVERRIDE
-- Performing Test COMPILER_SUPPORTS_WSUGGEST_OVERRIDE - Success
-- Enabling warning -Wsuggest-override
-- Performing Test COMPILER_SUPPORTS_WINCONSISTENT_MISSING_OVERRIDE
-- Performing Test COMPILER_SUPPORTS_WINCONSISTENT_MISSING_OVERRIDE - Failed
-- Performing Test COMPILER_SUPPORTS_WDUPLICATED_BRANCHES
-- Performing Test COMPILER_SUPPORTS_WDUPLICATED_BRANCHES - Success
-- Enabling warning -Wduplicated-branches
-- Performing Test COMPILER_SUPPORTS_WDUPLICATED_COND
-- Performing Test COMPILER_SUPPORTS_WDUPLICATED_COND - Success
-- Enabling warning -Wduplicated-cond
-- Performing Test COMPILER_SUPPORTS_WVLA
-- Performing Test COMPILER_SUPPORTS_WVLA - Success
-- Enabling error for -Wvla
-- Performing Test COMPILER_SUPPORTS_WIMPLICIT_FALLTHROUGH
-- Performing Test COMPILER_SUPPORTS_WIMPLICIT_FALLTHROUGH - Success
-- Enabling warning -Wimplicit-fallthrough
-- Performing Test COMPILER_SUPPORTS_WRETURN_TYPE
-- Performing Test COMPILER_SUPPORTS_WRETURN_TYPE - Success
-- Enabling error for -Wreturn-type
-- Performing Test COMPILER_SUPPORTS_WSHADOW
-- Performing Test COMPILER_SUPPORTS_WSHADOW - Success
-- Enabling warning -Wshadow
-- Performing Test COMPILER_SUPPORTS_WSIGN
-- Performing Test COMPILER_SUPPORTS_WSIGN - Success
-- Enabling warning -Wsign-compare
-- Performing Test COMPILER_SUPPORTS_WMISSING_INIT
-- Performing Test COMPILER_SUPPORTS_WMISSING_INIT - Success
-- Enabling warning -Wmissing-field-initializers
-- Performing Test COMPILER_SUPPORTS_WEMPTY_BODY
-- Performing Test COMPILER_SUPPORTS_WEMPTY_BODY - Success
-- Enabling warning -Wempty-body
-- Performing Test COMPILER_SUPPORTS_WREORDER
-- Performing Test COMPILER_SUPPORTS_WREORDER - Success
-- Enabling warning -Wreorder
-- Performing Test COMPILER_SUPPORTS_WMISMATCHED_TAGS
-- Performing Test COMPILER_SUPPORTS_WMISMATCHED_TAGS - Failed
-- Performing Test COMPILER_SUPPORTS_WIMPLICIT_FLOAT_CONVERSION
-- Performing Test COMPILER_SUPPORTS_WIMPLICIT_FLOAT_CONVERSION - Failed
-- Performing Test COMPILER_SUPPORTS_WPSABI
-- Performing Test COMPILER_SUPPORTS_WPSABI - Success
-- Disabling warning -Wpsabi
-- Found OpenGL: /usr/lib/x86_64-linux-gnu/libOpenGL.so   
-- Found GLEW: /usr/include  
-- Check for installed GLEW -- found
-- Found GLM: /usr/include (found suitable version "0.9.9.7", minimum required is "0.9.8") 
-- Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found version "1.2.11") 
-- Check for installed ZLIB -- found
-- Found CURL: /usr/lib/x86_64-linux-gnu/libcurl.so (found version "7.68.0")  
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.1") 
-- Checking for module 'cairo'
--   Found cairo, version 1.16.0
-- Found Cairo: /usr/lib/x86_64-linux-gnu/libcairo.so (found suitable version "1.16.0", minimum required is "1.12") 
-- Checking for module 'pixman-1'
--   Found pixman-1, version 0.38.4
-- Found Pixman: /usr/lib/x86_64-linux-gnu/libpixman-1.so (found suitable version "0.38.4", minimum required is "0.30") 
-- Found Boost: /usr/lib/x86_64-linux-gnu/cmake/Boost-1.71.0/BoostConfig.cmake (found suitable version "1.71.0", minimum required is "1.59.0")  
-- Checking for module 'ngspice'
--   Found ngspice, version 31
-- Found ngspice: /usr/include  
-- Found SWIG: /usr/bin/swig4.0 (found suitable version "4.0.1", minimum required is "3.0") 
-- Found PythonInterp: /usr/bin/python3 (found suitable version "3.8.5", minimum required is "3.3") 
-- Check for installed Python Interpreter -- found
-- Python module install path: lib/python3/dist-packages
-- Found PythonLibs: /usr/lib/x86_64-linux-gnu/libpython3.8.so (found suitable version "3.8.5", minimum required is "3.3") 
CMake Error at CMakeLists.txt:810 (message):
  Unable to find wxPython Classic, instead found wxPython Phoenix 4.0.7


-- Configuring incomplete, errors occurred!
See also "/home/pdp7/dev/kicad/kicad/build/debug/CMakeFiles/CMakeOutput.log".
See also "/home/pdp7/dev/kicad/kicad/build/debug/CMakeFiles/CMakeError.log".

on Ubuntu 20.04.1 LTS

I turned off KICAD_SCRIPTING_WXPYTHON and cmake completed:

pdp7@x1:~/dev/kicad/kicad/build/debug$ cmake -DKICAD_SCRIPTING_WXPYTHON=OFF -DKICAD_SCRIPTING_PYTHON3=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_PREFIX_PATH=/usr/local -DKICAD_CONFIG_DIR=kicad-master ../../
-- KiCad install dir: </usr/local>
-- Enabling warning -Wsuggest-override
-- Enabling warning -Wduplicated-branches
-- Enabling warning -Wduplicated-cond
-- Enabling error for -Wvla
-- Enabling warning -Wimplicit-fallthrough
-- Enabling error for -Wreturn-type
-- Enabling warning -Wshadow
-- Enabling warning -Wsign-compare
-- Enabling warning -Wmissing-field-initializers
-- Enabling warning -Wempty-body
-- Enabling warning -Wreorder
-- Disabling warning -Wpsabi
-- Check for installed GLEW -- found
-- Check for installed ZLIB -- found
-- Check for installed Python Interpreter -- found
-- Python module install path: lib/python3/dist-packages
-- Found wxWidgets: -L/usr/lib/x86_64-linux-gnu;-pthread;;;-lwx_gtk3u_gl-3.0;-lwx_gtk3u_aui-3.0;-lwx_gtk3u_adv-3.0;-lwx_gtk3u_html-3.0;-lwx_gtk3u_core-3.0;-lwx_baseu_net-3.0;-lwx_baseu-3.0;-lwx_gtk3u_propgrid-3.0;-lwx_baseu_xml-3.0;-lwx_gtk3u_stc-3.0 (found suitable version "3.0.4", minimum required is "3.0.0") 
-- Found Doxygen: /usr/bin/doxygen (found version "1.8.17") found components: doxygen dot 
-- Creating linux metadata
-- Found Git: /usr/bin/git (found version "2.25.1") 
-- Using Git to determine build version string.
-- Checking for module 'gtk+-3.0'
--   Found gtk+-3.0, version 3.24.20
-- Found OpenSSL: /usr/lib/x86_64-linux-gnu/libcrypto.so (found version "1.1.1f")  
-- S3DSG version: 2.0.0
-- Found Boost: /usr/lib/x86_64-linux-gnu/cmake/Boost-1.71.0/BoostConfig.cmake (found version "1.71.0") found components: unit_test_framework filesystem system 
-- Found wxWidgets: -L/usr/lib/x86_64-linux-gnu;-pthread;;;-lwx_gtk3u_gl-3.0;-lwx_gtk3u_aui-3.0;-lwx_gtk3u_adv-3.0;-lwx_gtk3u_html-3.0;-lwx_gtk3u_core-3.0;-lwx_baseu_net-3.0;-lwx_baseu-3.0;-lwx_baseu_xml-3.0;-lwx_gtk3u_stc-3.0 (found suitable version "3.0.4", minimum required is "3.0.0") 
-- Found Boost: /usr/lib/x86_64-linux-gnu/cmake/Boost-1.71.0/BoostConfig.cmake (found version "1.71.0") found components: unit_test_framework 
-- Configuring done
-- Generating done
-- Build files have been written to: /home/pdp7/dev/kicad/kicad/build/debug
pdp7@x1:~/dev/kicad/kicad/build/debug$ 

Add -DKICAD_SCRIPTING_WXPYTHON_PHOENIX=ON

1 Like

If I do that, then I get issue:

-- Python module install path: lib/python3/dist-packages
CMake Error at CMakeLists.txt:810 (message):
  Unable to find wxPython Classic, instead found wxPython Phoenix 4.0.7

I switched it to off and cmake completed. For now, I am ok with no in-app scripting console.

You have to clean cmake cache again after adding -DKICAD_SCRIPTING_WXPYTHON_PHOENIX

1 Like

I’ve not pursued getting WxPython to work, but I can import pcbnew from v5.99 now ok:

pdp7@x1:~/dev/kicad/kicad/build/debug$ PYTHONPATH=$PWD/pcbnew python3 ~/dev/oshpark/valet/vendor/kicad-cam.py ~/dev/oshpark/art/pumpkin-medium.kicad_pcb plot /tmp
/home/pdp7/dev/oshpark/art/pumpkin-medium.kicad_pcb
Executing full plot plan: Printing all to /tmp
Traceback (most recent call last):
  File "/home/pdp7/dev/oshpark/valet/vendor/kicad-cam.py", line 243, in <module>
    plot=board.plotAll(sys.argv[3])
  File "/home/pdp7/dev/oshpark/valet/vendor/kicad-cam.py", line 203, in plotAll
    self.__setPlotOptions(outputDir)
  File "/home/pdp7/dev/oshpark/valet/vendor/kicad-cam.py", line 152, in __setPlotOptions
    self.plotoptions.SetPlotPadsOnSilkLayer(False)
AttributeError: 'PCB_PLOT_PARAMS' object has no attribute 'SetPlotPadsOnSilkLayer'
pdp7@x1:~/dev/kicad/kicad/build/debug$ 

which shows me that it seems we will need to update our CAM script for V6.

@Seth_h is it stable enough for fabs to start doing this, do you think?

I don’t think so yet.

I just realized that KICAD_SCRIPTING_WXPYTHON=OFF seems to mean I can’t run any plugins ( V5.99: plugins missing after recent build ) so I do need to find a solution to getting past the error when KICAD_SCRIPTING_WXPYTHON=ON:

pdp7@x1:~/dev/kicad/kicad/build/debug$ cmake -DKICAD_SCRIPTING_WXPYTHON=ON -DKICAD_SCRIPTING_PYTHON3=ON -DCMAKE_BUILD_TYPE=Debug -DCMAKE_PREFIX_PATH=/usr/local -DKICAD_CONFIG_DIR=kicad-master ../../
-- Python module install path: lib/python3/dist-packages
-- Found PythonLibs: /usr/lib/x86_64-linux-gnu/libpython3.8.so (found suitable version "3.8.5", minimum required is "3.3") 
CMake Error at CMakeLists.txt:822 (message):
  Unable to find wxPython Classic, instead found wxPython Phoenix 4.0.7


-- Configuring incomplete, errors occurred!

What error do you get if you put -DKICAD_SCRIPTING_WXPYTHON_PHOENIX=ON instead of -DKICAD_SCRIPTING_WXPYTHON=ON?