# pyinstaller with RTK+VTK

**URL:** https://discourse.itk.org/t/pyinstaller-with-rtk-vtk/6556
**Category:** Algorithms
**Tags:** itk, python
**Created:** [April 8, 2024, 9:15am UTC](https://discourse.itk.org/t/pyinstaller-with-rtk-vtk/6556 "2024-04-08T09:15:28Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![zhangm](https://discourse.itk.org/letter_avatar_proxy/v4/letter/z/34f0e0/32.png) [@zhangm](https://discourse.itk.org/u/zhangm)
#### Post date: [April 8, 2024, 9:15am UTC](https://discourse.itk.org/t/pyinstaller-with-rtk-vtk/6556/1 "2024-04-08T09:15:28Z")

</div>

I use pyinstaller to generate a demo that can reconstruction data and show the result. The reconstruction is similar to FirstCudaReconstruction.py. My list of installed package is below.

```auto
Package Version
------------------------- ----------
altgraph 0.17.4
certifi 2021.10.8
click 8.1.7
colorama 0.4.6
contourpy 1.2.0
cycler 0.12.1
fonttools 4.47.2
importlib_metadata 7.1.0
importlib-resources 6.1.1
itk 5.4rc1
itk-core 5.4rc1
itk-cudacommon-cuda116 1.0.1
itk-filtering 5.4rc1
itk-io 5.4rc1
itk-numerics 5.4rc1
itk-registration 5.4rc1
itk-rtk-cuda116 2.5.0
itk-segmentation 5.4rc1
Jinja2 3.1.3
kiwisolver 1.4.5
MarkupSafe 2.1.5
matplotlib 3.8.4
numpy 1.24.1
nvidia-ml-py3 7.352.0
opencv-python 4.9.0.80
packaging 23.2
pefile 2023.2.7
pillow 10.2.0
pip 23.3.2
pyinstaller 5.9.0
pyinstaller-hooks-contrib 2024.3
pyparsing 3.1.1
pypiwin32 223
PyQt5 5.15.9
pyqt5-plugins 5.15.9.2.3
PyQt5-Qt5 5.15.2
PyQt5-sip 12.13.0
pyqt5-tools 5.15.9.3.3
python-dateutil 2.8.2
python-dotenv 1.0.1
pywin32 306
pywin32-ctypes 0.2.2
qt-material 2.14
qt5-applications 5.15.2.2.3
qt5-tools 5.15.2.1.3
scipy 1.12.0
setuptools 58.0.4
six 1.16.0
vtk 9.3.0
wheel 0.37.0
wincertstore 0.2
zipp 3.17.0

```

I use pyinstaller XX.spec to generate .exe file. The folder didn’t contain itk first, and I append `hiddenimports=['itk']` on the .spec file.  
The demo can run correctly on my computer, but an error occurred on other computers when the code runs to

> itk.RTK.CudaImage[itk.F, 3]

![企业微信截图_17125625312832](https://discourse.itk.org/uploads/default/original/2X/7/76733dfb46c21deba714b5c76c8b7972a66adaf1.png)  
I think may I didn’t correct pyinstaller itk, but I don’t know how to solve it. Any help would be appreciated.

---

<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: [April 8, 2024, 1:09pm UTC](https://discourse.itk.org/t/pyinstaller-with-rtk-vtk/6556/2 "2024-04-08T13:09:58Z")

</div>

I don’t know pyinstaller but it seems related to inability to locate Cuda DLLs, which is solved in the [example](https://github.com/RTKConsortium/RTK/blob/master/examples/FirstReconstruction/FirstCudaReconstruction.py#L13-L14) with the following line:

```Python
os.add_dll_directory(os.path.join(os.environ['CUDA_PATH'], 'bin'))

```

---

<div class="post-metadata">

### Author: ![zhangm](https://discourse.itk.org/letter_avatar_proxy/v4/letter/z/34f0e0/32.png) [@zhangm](https://discourse.itk.org/u/zhangm)
#### Post date: [April 9, 2024, 1:10am UTC](https://discourse.itk.org/t/pyinstaller-with-rtk-vtk/6556/3 "2024-04-09T01:10:29Z")

</div>

I print the path of Cuda when the demo run in other computer. It seems related to inability to locate Cuda DLLs.  
 ![企业微信截图_20240409091000](https://discourse.itk.org/uploads/default/original/2X/4/44c774670be0b32882ed327e5e1c835e6cc2d60a.png)  
Should the DLL used in code `itk.RTK.CudaImage[itk.F, 3]` not be \_ITKCommonPython instead of \_CudaCommonPython?

---

<div class="post-metadata">

### Author: ![zhangm](https://discourse.itk.org/letter_avatar_proxy/v4/letter/z/34f0e0/32.png) [@zhangm](https://discourse.itk.org/u/zhangm)
#### Post date: [April 11, 2024, 2:37am UTC](https://discourse.itk.org/t/pyinstaller-with-rtk-vtk/6556/4 "2024-04-11T02:37:52Z")

</div>

I copyed all the files about itk from site-packages, and replace the files on the exe folder.  
Before this operation, I also made the following attempts：

1. Pip uninstall itk and reinstall itk;
2. Add itk’s path to .spec;
3. Try pyinstaller from begin;

There was no error reported in the end.

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [April 24, 2024, 8:14pm UTC](https://discourse.itk.org/t/pyinstaller-with-rtk-vtk/6556/5 "2024-04-24T20:14:56Z")

</div>

Hi,

This post is helpful for the pyinstaller + ITK + RTK process:

> [@ITK Python pyinstaller issue](https://discourse.itk.org/t/itk-python-pyinstaller-issue/1520/4):
>
> You can try to use a hook file with this content: # This pyinstaller hook file does not support ITK with `WrapITK.pth`. from PyInstaller.utils.hooks import collect\_data\_files hiddenimports = ['new'] # If ITK is pip installed, gets all the files. itk\_datas = collect\_data\_files('itk', include\_py\_files=True) datas = [x for x in itk\_datas if '\_\_pycache\_\_' not in x[0]] Save the code above in a file called hook-itk.py and add --additional-hooks-dir= to the command line calling pyinstaller, with t…

---

<div class="post-metadata">

### Author: ![zhangm](https://discourse.itk.org/letter_avatar_proxy/v4/letter/z/34f0e0/32.png) [@zhangm](https://discourse.itk.org/u/zhangm)
#### Post date: [April 26, 2024, 7:59am UTC](https://discourse.itk.org/t/pyinstaller-with-rtk-vtk/6556/6 "2024-04-26T07:59:35Z")

</div>

Thank you for your reply. I have try this method on the fist, but it didn’t work.

> [@pyinstaller with RTK+VTK](https://discourse.itk.org/t/pyinstaller-with-rtk-vtk/6556/4):
>
> I copyed all the files about itk from site-packages, and replace the files on the exe folder. Before this operation, I also made the following attempts： Pip uninstall itk and reinstall itk; Add itk’s path to .spec; Try pyinstaller from begin; There was no error reported in the end.

But when I try the three attempts and then use that method again. It works. I don’t know why, but at least the result is good.

---

<div class="post-metadata">

### Author: ![guo7212](https://discourse.itk.org/letter_avatar_proxy/v4/letter/g/7ab992/32.png) [@guo7212](https://discourse.itk.org/u/guo7212)
#### Post date: [November 22, 2024, 8:29am UTC](https://discourse.itk.org/t/pyinstaller-with-rtk-vtk/6556/7 "2024-11-22T08:29:49Z")

</div>

> [@pyinstaller with RTK+VTK](#):
>
> Add itk’s path to .spec

Can you explain more about that?

---

<div class="post-metadata">

### Author: ![zhangm](https://discourse.itk.org/letter_avatar_proxy/v4/letter/z/34f0e0/32.png) [@zhangm](https://discourse.itk.org/u/zhangm)
#### Post date: [November 25, 2024, 3:25am UTC](https://discourse.itk.org/t/pyinstaller-with-rtk-vtk/6556/8 "2024-11-25T03:25:55Z")

</div>

just like this:

 ![image](https://discourse.itk.org/uploads/default/original/2X/8/8956f58085ee6e7c8e35c57afea924e10ca41ce9.png)

---

<div class="post-metadata">

### Author: ![guo7212](https://discourse.itk.org/letter_avatar_proxy/v4/letter/g/7ab992/32.png) [@guo7212](https://discourse.itk.org/u/guo7212)
#### Post date: [December 11, 2024, 3:17am UTC](https://discourse.itk.org/t/pyinstaller-with-rtk-vtk/6556/9 "2024-12-11T03:17:42Z")

</div>

Thanks.
