ITK Python Wrapping error: void value not ignored as it ought to be

Building in debug mode from master.

First time encountered here:

Wrapping/Generators/Python/PyBase/ITKPyBasePython.cpp: In function ‘void init_ITKPyBasePython()’:
Wrapping/Generators/Python/PyBase/ITKPyBasePython.cpp:3857:52: error: void value not ignored as it ought to be
     PyObject * pyBaseModule = PyInit__pyBasePython();

And also later:

Wrapping/Modules/ITKCommon/ITKCommonPython.cpp: In function ‘void init_ITKCommonPython()’:
Wrapping/Modules/ITKCommon/ITKCommonPython.cpp:3925:66: error: void value not ignored as it ought to be
     PyObject * itkFixedArrayModule = PyInit__itkFixedArrayPython();
                                                                  ^
Wrapping/Modules/ITKCommon/ITKCommonPython.cpp:3935:58: error: void value not ignored as it ought to be
     PyObject * itkVectorModule = PyInit__itkVectorPython();
                                                          ^
Wrapping/Modules/ITKCommon/ITKCommonPython.cpp:3945:76: error: void value not ignored as it ought to be
     PyObject * itkCovariantVectorModule = PyInit__itkCovariantVectorPython();
                                                                            ^
Wrapping/Modules/ITKCommon/ITKCommonPython.cpp:3955:56: error: void value not ignored as it ought to be
     PyObject * itkPointModule = PyInit__itkPointPython();

Has anyone faced this before? Thanks!

Issue found. I was linking to a VTK which was using python2.7, instead of python3.6.

thanks to @jcfr for help.

1 Like

Hi @phcerdan,
I built VTK with Python version 3.6. However, ITK still throws such above exception. Do you know what setting in ITK to make it use python version 3.6 instead ? Seems like my ITK is still using Python 2.7

I guess you can use the CMake option cmake -DPYTHON_EXECUTABLE:PATH=/path/bin/python3 ../ITK-source

In your case, if you have built VTK with python3.6, do the the same with ITK in a fresh build.

Yes, my python is in version 3.6
phtran@X230:~/workingspace/InsightToolkit-5.0.1/build$ grep PYTHON_EXECUTABLE CMakeCache.txt
PYTHON_EXECUTABLE:FILEPATH=/usr/bin/python
//ADVANCED property for variable: PYTHON_EXECUTABLE
PYTHON_EXECUTABLE-ADVANCED:INTERNAL=1
phtran@X230:~/workingspace/InsightToolkit-5.0.1/build$ python --version
Python 3.6.8

But I still got errors:
/home/phtran/workingspace/InsightToolkit-5.0.1/build/Wrapping/Generators/Python/PyBase/ITKPyBasePython.cpp: In function ‘void init_ITKPyBasePython()’:
/home/phtran/workingspace/InsightToolkit-5.0.1/build/Wrapping/Generators/Python/PyBase/ITKPyBasePython.cpp:3864:52: error: void value not ignored as it ought to be
PyObject * pyBaseModule = PyInit__pyBasePython();

Just to be sure, what is the result of the following bash command?

which python
1 Like

Hi Pablo,
It is:
phtran@X230:~$ which python
/usr/bin/python

Not sure then @Phong_Tran. Have you tried with a complete fresh build of ITK? i.e removing the build folder completely.

The PYTHON_EXECUTABLE CMakeCache.txt variable is important, as @phcerdan.

Other CMakeCache.txt variables to check:

  • PYTHON_INCLUDE_DIR
  • PYTHON_LIBRARY

These should correspond to the PYTHON_EXECUTABLE.

1 Like

I tried to change the variable : PYTHON_LIBRARY from FILEPATH TO PATH as below:
From: PYTHON_LIBRARY:FILEPATH=/usr/lib/x86_64-linux-gnu/libpython3.6m.so
To: PYTHON_LIBRARY:PATH=/usr/lib/python3.6

I dont get the above errors, however, I get the other errors:

/usr/local/lib/libvtkWrappingPython36Core-8.2.so.1: error: undefined reference to ‘PyObject_Hash’
/usr/local/lib/libvtkWrappingPython36Core-8.2.so.1: error: undefined reference to ‘PyObject_GetBuffer’
/usr/local/lib/libvtkWrappingPython36Core-8.2.so.1: error: undefined reference to ‘PyObject_Repr’
/usr/local/lib/libvtkWrappingPython36Core-8.2.so.1: error: undefined reference to ‘PyExc_ValueError’
/usr/local/lib/libvtkWrappingPython36Core-8.2.so.1: error: undefined reference to ‘PyLong_AsLong’
/usr/local/lib/libvtkWrappingPython36Core-8.2.so.1: error: undefined reference to ‘PyBool_Type’
/usr/local/lib/libvtkWrappingPython36Core-8.2.so.1: error: undefined reference to ‘PyObject_GetAttr’
/usr/local/lib/libvtkWrappingPython36Core-8.2.so.1: error: undefined reference to ‘PyExc_KeyError’
/usr/local/lib/libvtkWrappingPython36Core-8.2.so.1: error: undefined reference to ‘_Py_TrueStruct’
/usr/local/lib/libvtkWrappingPython36Core-8.2.so.1: error: undefined reference to ‘PyNumber_And’
/usr/local/lib/libvtkWrappingPython36Core-8.2.so.1: error: undefined reference to ‘PyTuple_Pack’
/usr/local/lib/libvtkWrappingPython36Core-8.2.so.1: error: undefined reference to ‘PyUnicode_GetLength’
/usr/local/lib/libvtkWrappingPython36Core-8.2.so.1: error: undefined reference to ‘Py_ReprLeave’
/usr/local/lib/libvtkWrappingPython36Core-8.2.so.1: error: undefined reference to ‘_Py_HashPointer’
/usr/local/lib/libvtkWrappingPython36Core-8.2.so.1: error: undefined reference to ‘PyObject_Str’
/usr/local/lib/libvtkWrappingPython36Core-8.2.so.1: error: undefined reference to ‘PyObject_GetAttrString’
/usr/local/lib/libvtkWrappingPython36Core-8.2.so.1: error: undefined reference to ‘PyModule_Type’
/usr/local/lib/libvtkWrappingPython36Core-8.2.so.1: error: undefined reference to ‘PyErr_Restore’
/usr/local/lib/libvtkWrappingPython36Core-8.2.so.1: error: undefined reference to ‘PyType_IsSubtype’
/usr/local/lib/libvtkWrappingPython36Core-8.2.so.1: error: undefined reference to ‘PyModule_GetDict’
/usr/local/lib/libvtkWrappingPython36Core-8.2.so.1: error: undefined reference to ‘PyNumber_Power’
/usr/local/lib/libvtkWrappingPython36Core-8.2.so.1: error: undefined reference to ‘PyNumber_Index’
/usr/local/lib/libvtkWrappingPython36Core-8.2.so.1: error: undefined reference to ‘PyUnicode_InternFromString’
/usr/local/lib/libvtkWrappingPython36Core-8.2.so.1: error: undefined reference to ‘PyTuple_New’
/usr/local/lib/libvtkWrappingPython36Core-8.2.so.1: error: undefined reference to ‘PyNumber_Divmod’
/usr/local/lib/libvtkWrappingPython36Core-8.2.so.1: error: undefined reference to ‘PyUnicode_GetSize’
/usr/local/lib/libvtkWrappingPython36Core-8.2.so.1: error: undefined reference to ‘PyExc_KeyboardInterrupt’
/usr/local/lib/libvtkWrappingPython36Core-8.2.so.1: error: undefined reference to ‘_Py_NoneStruct’
/usr/local/lib/libvtkWrappingPython36Core-8.2.so.1: error: undefined reference to ‘PyExc_AttributeError’
/usr/local/lib/libvtkWrappingPython36Core-8.2.so.1: error: undefined reference to ‘PyNumber_Float’
/usr/local/lib/libvtkWrappingPython36Core-8.2.so.1: error: undefined reference to ‘PyNumber_Add’

There are a lots of “undefnied reference”. Not sure if you have ever seen them ?

1 Like

Not a surprise @Phong_Tran
PYTHON_LIBRARY:FILEPATH=/usr/lib/x86_64-linux-gnu/libpython3.6m.so
is a full path to the python library, but you are providing
PYTHON_LIBRARY:PATH=/usr/lib/python3.6
which is not a path to the library for sure.

Zooming out a little bit:
The error I reported originally was solved rebuilding VTK with the same python I wanted to use in ITK, so I solved the problem first rebuilding VTK, and then ITK, with the same python.

I recommend you to do the same.

1 Like

Thanks @phcerdan, that works like a charm. I have another question that might not be related to the original question on the thread. But I still want to ask here that when I use the ITKVtkGluePython.py like the below snippet code

import sys
import os
import itk
import vtk
itkToVtkFilter = ImageToVTKImageFilter[ImageType].New()

It throws exception:

╰─$ ~/workingspace/VTK-8.2.0/build/bin/vtkpython itk_vtk_server.py ~/tmp/dicom_data/CT_BVND2/1.3.46.670589.33.1.63686419356542268400001.5244014515565132624
Traceback (most recent call last):
File “itk_vtk_server.py”, line 58, in
ImageToVTKImageFilter = itk.ImageToVTKImageFilter[ImageType]
File “/home/phongtd/.local/lib/python3.6/site-packages/itkLazy.py”, line 52, in getattribute
itkBase.LoadModule(module, namespace)
File “/home/phongtd/.local/lib/python3.6/site-packages/itkBase.py”, line 128, in LoadModule
module = loader.load(swigModuleName)
File “/home/phongtd/.local/lib/python3.6/site-packages/itkBase.py”, line 253, in load
return importlib.import_module(name)
File “/usr/lib/python3.6/importlib/init.py”, line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File “”, line 994, in _gcd_import
File “”, line 971, in _find_and_load
File “”, line 955, in _find_and_load_unlocked
File “”, line 665, in _load_unlocked
File “”, line 678, in exec_module
File “”, line 219, in _call_with_frames_removed
File “/home/phongtd/.local/lib/python3.6/site-packages/itk/Configuration/…/ITKVtkGluePython.py”, line 15, in
ctypes.CDLL(_vtkIOlib, ctypes.RTLD_GLOBAL)
File “/usr/lib/python3.6/ctypes/init.py”, line 348, in init
self._handle = _dlopen(self._name, mode)
OSError: libvtkIO-8.2.so.1: cannot open shared object file: No such file or directory

I have no idea where to find the “libvtkIO-8.2.so.1”, since it does not exist in my VTK build as well in my installing dir: /usr/local/lib. Those errors might be related to the question I asked before on this thread https://discourse.itk.org/t/itk-imagetovtkimagefilter-crashing-python/2018/4

@matt.mccormick, did you manage to isolate the issue ?

Glad that it worked!
About the new question, I do not know, never faced it. But better ask in a new thread, or follow up in an existing conversation. It’s out of topic in this one.

1 Like

Thank you @phcerdan, I already replied on the existing conversation (itk.ImageToVTKImageFilter crashing Python). Hope that help others.

1 Like