# simple ITK in windows container

**URL:** https://discourse.itk.org/t/simple-itk-in-windows-container/5169
**Category:** Uncategorized
**Tags:** python, docker, simpleitk
**Created:** [July 8, 2022, 12:45am UTC](https://discourse.itk.org/t/simple-itk-in-windows-container/5169 "2022-07-08T00:45:40Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Sowmya\_Rajesh](https://discourse.itk.org/user_avatar/discourse.itk.org/sowmya_rajesh/32/2770_2.png) [@Sowmya\_Rajesh](https://discourse.itk.org/u/Sowmya_Rajesh)
#### Post date: [July 8, 2022, 12:45am UTC](https://discourse.itk.org/t/simple-itk-in-windows-container/5169/1 "2022-07-08T00:45:40Z")

</div>

I am trying to use simpleITK inside the docker windows container. The container is built without any error. But when I run the container, I am getting the following error.

_Traceback (most recent call last):_

- File “c:\helloworld.py”, line 1, in \*
- import SimpleITK as sitk\*
- File “C:\Python\lib\site-packages\SimpleITK\__init_\_.py”, line 18, in \*
- from SimpleITK.SimpleITK import \*\*
- File “C:\Python\lib\site-packages\SimpleITK\SimpleITK.py”, line 13, in \*
- from . import \_SimpleITK\*  
_ImportError: DLL load failed while importing \_SimpleITK: The specified module could not be found._

Here is my Dockerfile

**FROM python:3.9-windowsservercore**  
**COPY helloworld.py c:/helloworld.py**  
**COPY requirements.txt c:/requirements.txt**  
**RUN python -m pip install -r c:/requirements.txt**  
**CMD [“python” ,“c:/helloworld.py”]**

Here is the helloworld.py

**import SimpleITK as sitk**  
**print(“Hello World !!!”)**  
**img = sitk.ReadImage(’./input/sample.mha’)**  
**print(img.GetDimension())**  
**print(img.GetSize())**

---

<div class="post-metadata">

### Author: ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)
#### Post date: [July 8, 2022, 6:13pm UTC](https://discourse.itk.org/t/simple-itk-in-windows-container/5169/2 "2022-07-08T18:13:17Z")

</div>

Possibly "C:\Python\lib\site-packages" is not in the PYTHONPATH, add it:

```auto
set PYTHONPATH=%PYTHONPATH%;C:\Python\lib\site-packages\
```

---

<div class="post-metadata">

### Author: ![Sowmya\_Rajesh](https://discourse.itk.org/user_avatar/discourse.itk.org/sowmya_rajesh/32/2770_2.png) [@Sowmya\_Rajesh](https://discourse.itk.org/u/Sowmya_Rajesh)
#### Post date: [July 11, 2022, 8:02pm UTC](https://discourse.itk.org/t/simple-itk-in-windows-container/5169/3 "2022-07-11T20:02:09Z")

</div>

Thanks. I set the environment path. I still get this error when running the container.

` **import SimpleITK`\*\*

**` File "C:\Python\lib\site-packages\SimpleITK\ __init__.py", line 18, in <module>`**

**``**

**` from SimpleITK.SimpleITK import *`**

**` File "C:\Python\lib\site-packages\SimpleITK\SimpleITK.py", line 13, in <module`**

**`>`**

**` from . import _SimpleITK`**

**`ImportError: DLL load failed while importing _SimpleITK: The specified module co`**

**`uld not be found.`**

---

<div class="post-metadata">

### Author: ![dchen](https://discourse.itk.org/user_avatar/discourse.itk.org/dchen/32/34_2.png) [@dchen](https://discourse.itk.org/u/dchen)
#### Post date: [July 14, 2022, 6:51pm UTC](https://discourse.itk.org/t/simple-itk-in-windows-container/5169/4 "2022-07-14T18:51:13Z")

</div>

It looks like it’s not finding the SimpleITK shared library. There should be a ‘.pyd’ file in that same directory, **C:\Python\lib\site-packages\SimpleITK`**.

I wrote a little script to inspect my SimpleITK installation:

```
import os
import inspect
import SimpleITK as sitk

sitk_file = inspect.getfile(sitk)
print(sitk_file)

sitk_dir = os.path.dirname(sitk_file)
print(sitk_dir)

print(os.listdir(sitk_dir))

```

And here’s what the output looks like on my Window system:

```
C:\Users\dchen\anaconda3\envs\sitkpy\lib\site-packages\SimpleITK\ __init__.py
C:\Users\dchen\anaconda3\envs\sitkpy\lib\site-packages\SimpleITK
['docs', 'extra.py', 'SimpleITK.py', '_SimpleITK.cp39-win_amd64.pyd', '_version.py', ' __init__.py', ' __pycache__']

```

It seems like your system isn’t finding that ‘.pyd’ file.

---

<div class="post-metadata">

### Author: ![Sowmya\_Rajesh](https://discourse.itk.org/user_avatar/discourse.itk.org/sowmya_rajesh/32/2770_2.png) [@Sowmya\_Rajesh](https://discourse.itk.org/u/Sowmya_Rajesh)
#### Post date: [July 18, 2022, 6:40pm UTC](https://discourse.itk.org/t/simple-itk-in-windows-container/5169/5 "2022-07-18T18:40:24Z")

</div>

> [@Sowmya\_Rajesh](#):
>
> ImportError: DLL load failed while importing \_SimpleITK:

thanks,  
It helped. I checked the file was available under c:/Python/lib/site-packages/SimpleITK  
I also installed the vc++ using the following command.  
RUN [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; `	Invoke-WebRequest "https://aka.ms/vs/17/release/vc_redist.x64.exe" -OutFile "vc_redist.x64.exe";`  
Start-Process -filepath C:\vc\_redist.x64.exe -ArgumentList “/install”, “/passive”, “/norestart” -Passthru | Wait-Process; `  
Remove-Item -Force vc\_redist.x64.exe;

ENV PYTHONPATH=%PYTHONPATH%;C:/Python/lib/site-packages/

I am able to run the application inside the docker container.  
Thanks again.

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [July 18, 2022, 6:45pm UTC](https://discourse.itk.org/t/simple-itk-in-windows-container/5169/6 "2022-07-18T18:45:26Z")

</div>

Ahh, the windows docker containers are missing a needed MSVC C++ runtime libraries required by the loading of the SimpleITK shared library.

Thanks for posting the solution!
