Building ITK with python wrappers

Hi,

I was trying to configure ITK (latest master) with CMake with option ITK_WRAP_PYTHON on but it keeps failing due to this error:

CMake Error at CMake/ITKModuleTest.cmake:196 (message):
D:/lib/pyITK_build/CMakeTmp/Wrapping/Generators/Python/WrapITK.pth must
exist.
Call Stack (most recent call first):
Modules/Remote/RTK/test/CMakeLists.txt:299 (itk_python_add_test)

Python is correctly installed and also in PATH of my windows machine. Can you point me in the right direction?
I’m configuring the project to be built in visual studio 2017.

Important note, this happens when turning on Module_RTK option

@LucasGandel and/or @simon.rit should be best able to answer this question.

Thanks!

By the way, I managed to configure by turning off the testing option, and I’m currently building without issues.
Hope it’s useful info.

I admit I never turn on testing when building RTK wrappings… Thanks for the report, I can reproduce this. I have opened an issue to track this but since RTK has no python tests, I would advise you to continue like you did. I’ll handle the issue asap (but it doesn’t seem urgent).

2 Likes

Following on the topic.
I managed to compile with CUDA enabled after turning off RTK_BUILD_APPLICATIONS and produce .py files under build\Wrapping\Generators\Python\itk.
I tried to create a venv in the build directory. Then after I copied WrapITK.pth into mybuild\venv\Lib\site-packages I tried importing itk (successfully) and rtk (seemingly without errors) inside a venv python shell.
However when I try to declare something like rtk.ThreeDCircularProjectionGeometry.New() I get:

File “D:\lib\pyITK_build\Wrapping\Generators\Python\itk\support..\RTKPython.py”, line 13, in
from . import _RTKPython
ImportError: DLL load failed while importing _RTKPython: cannot find specified module.

I’m kinda lost. Any idea of why this happens?

What I normally do is set PY_SITE_PACKAGES_PATH (and CMAKE_INSTALL_PREFIX) to some locations and install the build (with make install in my case). Then I set the pth file to the same PY_SITE_PACKAGES_PATH. Can you check if it helps?
Another problem might be that the DLLs are not in the path and you need to add them.

1 Like

I tried to change the PY_SITE_PACKAGES_PATH and CMAKE_INSTALL_PREFIX. After correctly setting the pth file to accommodate for this however I’m at the same error.
For the DLLs I think you may have a point as I am building statically (I added the .libs to the path to no avail). I will try to rebuild the whole package with SHARED_LIBS ON!

Same build but with SHARED_LIBS ON gives error only on project RTKpython for multiple symbol definition/s

e.g. : itkRTK-5.3.lib(itkRTK-5.3.dll) : error LNK2005: "protected: virtual void __cdecl itk::ImageSource<class itk::CudaImage<float,3> >::AllocateOutputs(void)" (?AllocateOutputs@?$ImageSource@V?$CudaImage@M$02@itk@@@itk@@MEAAXXZ) already defined in itkCudaImageToImageFilterPython.obj

I have tested it with the static version. I can reproduce the “DLL load” problem, which only occurs with Cuda on Windows. It works without Cuda on Windows and it works with Cuda on Linux. I don’t really understand why it does not load _RTKPython.pyd… The surprising bit is that an application with similar dependencies as _RTKPython.pyd (ITKCudaCommon.lib and itkRTK-5.3.lib) does not seem to have the same problem… I do not know how to fix this!

I don’t think the problem with SHARED_LIBS ON is the same problem but I’ll try to have a look too.

2 Likes

Thanks for the help Simon!

1 Like