# Building ITK with python wrappers

**URL:** https://discourse.itk.org/t/building-itk-with-python-wrappers/4396
**Category:** Beginner Questions
**Tags:** python, build
**Created:** [September 2, 2021, 1:49pm UTC](https://discourse.itk.org/t/building-itk-with-python-wrappers/4396 "2021-09-02T13:49:39Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![Gabriele\_Belotti](https://discourse.itk.org/user_avatar/discourse.itk.org/gabriele_belotti/32/825_2.png) [@Gabriele\_Belotti](https://discourse.itk.org/u/Gabriele_Belotti)
#### Post date: [September 2, 2021, 1:49pm UTC](https://discourse.itk.org/t/building-itk-with-python-wrappers/4396/1 "2021-09-02T13:49:39Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Gabriele\_Belotti](https://discourse.itk.org/user_avatar/discourse.itk.org/gabriele_belotti/32/825_2.png) [@Gabriele\_Belotti](https://discourse.itk.org/u/Gabriele_Belotti)
#### Post date: [September 2, 2021, 2:28pm UTC](https://discourse.itk.org/t/building-itk-with-python-wrappers/4396/2 "2021-09-02T14:28:14Z")

</div>

Important note, this happens when turning on Module\_RTK option

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [September 2, 2021, 3:09pm UTC](https://discourse.itk.org/t/building-itk-with-python-wrappers/4396/3 "2021-09-02T15:09:03Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Gabriele\_Belotti](https://discourse.itk.org/user_avatar/discourse.itk.org/gabriele_belotti/32/825_2.png) [@Gabriele\_Belotti](https://discourse.itk.org/u/Gabriele_Belotti)
#### Post date: [September 2, 2021, 3:27pm UTC](https://discourse.itk.org/t/building-itk-with-python-wrappers/4396/4 "2021-09-02T15:27:18Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![simon.rit](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/f08c70/32.png) [@simon.rit](https://discourse.itk.org/u/simon.rit)
#### Post date: [September 2, 2021, 3:39pm UTC](https://discourse.itk.org/t/building-itk-with-python-wrappers/4396/5 "2021-09-02T15:39:41Z")

</div>

I admit I never turn on testing when building RTK wrappings… Thanks for the report, I can reproduce this. I have opened an [issue](https://github.com/SimonRit/RTK/issues/434) 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).

---

<div class="post-metadata">

### Author: ![Gabriele\_Belotti](https://discourse.itk.org/user_avatar/discourse.itk.org/gabriele_belotti/32/825_2.png) [@Gabriele\_Belotti](https://discourse.itk.org/u/Gabriele_Belotti)
#### Post date: [September 10, 2021, 3:01pm UTC](https://discourse.itk.org/t/building-itk-with-python-wrappers/4396/6 "2021-09-10T15:01:53Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![simon.rit](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/f08c70/32.png) [@simon.rit](https://discourse.itk.org/u/simon.rit)
#### Post date: [September 14, 2021, 12:53pm UTC](https://discourse.itk.org/t/building-itk-with-python-wrappers/4396/7 "2021-09-14T12:53:16Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Gabriele\_Belotti](https://discourse.itk.org/user_avatar/discourse.itk.org/gabriele_belotti/32/825_2.png) [@Gabriele\_Belotti](https://discourse.itk.org/u/Gabriele_Belotti)
#### Post date: [September 14, 2021, 3:20pm UTC](https://discourse.itk.org/t/building-itk-with-python-wrappers/4396/8 "2021-09-14T15:20:30Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![Gabriele\_Belotti](https://discourse.itk.org/user_avatar/discourse.itk.org/gabriele_belotti/32/825_2.png) [@Gabriele\_Belotti](https://discourse.itk.org/u/Gabriele_Belotti)
#### Post date: [September 15, 2021, 2:54pm UTC](https://discourse.itk.org/t/building-itk-with-python-wrappers/4396/9 "2021-09-15T14:54:46Z")

</div>

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`

---

<div class="post-metadata">

### Author: ![simon.rit](https://discourse.itk.org/letter_avatar_proxy/v4/letter/s/f08c70/32.png) [@simon.rit](https://discourse.itk.org/u/simon.rit)
#### Post date: [September 29, 2021, 3:13pm UTC](https://discourse.itk.org/t/building-itk-with-python-wrappers/4396/10 "2021-09-29T15:13:11Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![Gabriele\_Belotti](https://discourse.itk.org/user_avatar/discourse.itk.org/gabriele_belotti/32/825_2.png) [@Gabriele\_Belotti](https://discourse.itk.org/u/Gabriele_Belotti)
#### Post date: [October 1, 2021, 8:00am UTC](https://discourse.itk.org/t/building-itk-with-python-wrappers/4396/11 "2021-10-01T08:00:42Z")

</div>

Thanks for the help Simon!
