Problem Summary
importing pcbnew in a python script from within an Ubuntu 22.04 based docker image works but the same import fails with the error below when run from pytest in the same environment. I’m not sure if the issue lies in how I’ve linked in the kicad swig interface module or is something inherent with pytest or something else.
kicad_fplib_tools/utils.py:15: in <module>
import pcbnew
/usr/lib/kicad/lib/python3/dist-packages/pcbnew.py:15: in <module>
import _pcbnew
E ImportError: /lib/x86_64-linux-gnu/libfreeimage.so.3: undefined symbol: _TIFFDataSize, version LIBTIFF_4.0
More Details
I’m trying to update a bunch of scripts I developed for KiCad 5.x to work with v7.0.0 and in the process I’m setting up a Dockerfile to automate testing. I’ve setup got an Ubuntu 22.04 Docker image that installs KiCad 7.0.0 using apt and downloads + unpacks a FreeCAD AppImage. I run all my local tests on this library and others using pipenv so I’m setting things up to work directly through that.
I currently have the pcbnew module able to be imported after installation by adding the 2 lines below to the Dockerfile after installing KiCad 7.0.0. My previous installations of KiCad added the Swig interface to my pythonpath automatically and this step wasn’t required. If anyone has advice on this too, it would be greatly appreciated - I may create a new topic for this soon too.
ENV PYTHONPATH=${PYTHONPATH}:/usr/lib/kicad/lib/python3/dist-packages
ENV LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/lib/kicad/lib/x86_64-linux-gnu
When running python within a container using the image, I am able to import the ‘pcbnew’ module without any issues. However when I attempt the import from within pytest, I get the error message quoted above in Problem Summary.
For further clarity, this is a copy paste from the import working correctly from a shell in the container using python directly.
$ docker run --rm -it --entrypoint bash freecad_kicad_tools
root@23e5e687da57:/project_dir# pipenv run python
Python 3.10.6 (main, Nov 14 2022, 16:10:14) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pcbnew
>>> pcbnew.F_Cu
0
And now trying the same while running pytest.
$ docker run --rm -it --entrypoint bash freecad_kicad_toolsroot@e575c4c552c3:/project_dir# pipenv run pytest
===================================================== test session starts ======================================================
platform linux -- Python 3.10.6, pytest-7.2.1, pluggy-1.0.0
rootdir: /project_dir, configfile: setup.cfg, testpaths: tests/
collecting ...
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> PDB set_trace (IO-capturing turned off) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
> /project_dir/tests/unit/test_shape_generators.py(16)<module>()
-> from kicad_fplib_tools.utils import KiCadLayer
(Pdb) import pcbnew
*** ImportError: /lib/x86_64-linux-gnu/libfreeimage.so.3: undefined symbol: _TIFFDataSize, version LIBTIFF_4.0
My Environment
- kicad-cli version > 7.0.0
- pipenv run python --version > Python 3.10.6
- pipenv run pytest --version > pytest 7.2.1
- OS: Ubuntu 22.04.1 LTS (within a docker)