# SimpleITK install fails on Windows

**URL:** <https://discourse.slicer.org/t/simpleitk-install-fails-on-windows/23373>\
**Category:** Development\
**Created:** [May 11, 2022, 1:22pm UTC](https://discourse.slicer.org/t/simpleitk-install-fails-on-windows/23373 "2022-05-11T13:22:25Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![keri](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/keri/32/11618_2.png) [@keri](https://discourse.slicer.org/u/keri)\
**Post date:** [May 11, 2022, 1:22pm UTC](https://discourse.slicer.org/t/simpleitk-install-fails-on-windows/23373/1 "2022-05-11T13:22:25Z")

</div>

Hi,

I just tried Slicer 3D [master branch](https://github.com/Slicer/Slicer/commit/1efef1b35da0f95835c4f56def90629782cd492e) clean build on Windows 11, [VS 2022](https://slicer.readthedocs.io/en/latest/developer_guide/build_instructions/windows.html#install-prerequisites) and I get error:

```auto
  Performing install step for 'SimpleITK'
  -- SimpleITK: Removing 'install' log files
  -- SimpleITK: SimpleITK_WORKING_DIR: C:/C/r/SimpleITK-build/SimpleITK-build/Wrapping/Python
  -- SimpleITK: C:/C/r/python-install/bin/PythonSlicer.exe;setup.py;install
  -- SimpleITK: Errors detected - See below.
  CMake Error at C:/C/r/slicersources-src/CMake/ExternalProjectForNonCMakeProject.cmake:104 (message):
    SimpleITK: install step failed with exit code '1'.

    Outputs also captured in C:/C/r/SimpleITK_install_step_output.txt and
    C:/C/r/SimpleITK_install_step_error.txt.

    Setting env. variable EP_EXECUTE_DISABLE_CAPTURE_OUTPUTS to 1 allows to
    disable file capture.

  Call Stack (most recent call first):
    C:/C/r/SimpleITK_install_step.cmake:3 (ExternalProject_Execute)

  Traceback (most recent call last):
    File "C:\C\r\SimpleITK-build\SimpleITK-build\Wrapping\Python\setup.py", line 14, in <module>
      from SimpleITK._version import __version__
    File "C:\C\r\SimpleITK-build\SimpleITK-build\Wrapping\Python\SimpleITK\ __init__.py", line 18, in <module>
      from SimpleITK.SimpleITK import *
    File "C:\C\r\SimpleITK-build\SimpleITK-build\Wrapping\Python\SimpleITK\SimpleITK.py", line 13, in <module>
      from . import _SimpleITK
  ImportError: DLL load failed while importing _SimpleITK: The specified module could not be found.

```

I guess some \_SimpleITK’s dependencies not found.  
There is no such problem on Ubuntu

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [May 11, 2022, 2:13pm UTC](https://discourse.slicer.org/t/simpleitk-install-fails-on-windows/23373/2 "2022-05-11T14:13:48Z")

</div>

It is almost always due to some invasive Python environment, which got added to the system PATH or other environment variables. See some more information and solution here: [Windows — 3D Slicer documentation](https://slicer.readthedocs.io/en/latest/developer_guide/build_instructions/windows.html#errors-related-to-python)

If the solution described there does not work then please copy here the error messages that the build output refers to.

---

<div class="post-metadata">

**Author:** ![keri](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/keri/32/11618_2.png) [@keri](https://discourse.slicer.org/u/keri)\
**Post date:** [May 11, 2022, 2:59pm UTC](https://discourse.slicer.org/t/simpleitk-install-fails-on-windows/23373/3 "2022-05-11T14:59:05Z")

</div>

No I don’t have any other python installed and Windows is almost clean (installed it yesterday as virtual machine).

> [@lassoan](#):
>
> If the solution described there does not work then please copy here the error messages that the build output refers to.

Do you mean the content of `C:/C/r/SimpleITK_install_step_output.txt` and `C:/C/r/SimpleITK_install_step_error.txt` files?  
If so then `SimpleITK_install_step_output.txt` is empty now and `SimpleITK_install_step_error.txt` contains the same error:

```auto
  Traceback (most recent call last):
    File "C:\C\r\SimpleITK-build\SimpleITK-build\Wrapping\Python\setup.py", line 14, in <module>
      from SimpleITK._version import __version__
    File "C:\C\r\SimpleITK-build\SimpleITK-build\Wrapping\Python\SimpleITK\ __init__.py", line 18, in <module>
      from SimpleITK.SimpleITK import *
    File "C:\C\r\SimpleITK-build\SimpleITK-build\Wrapping\Python\SimpleITK\SimpleITK.py", line 13, in <module>
      from . import _SimpleITK
  ImportError: DLL load failed while importing _SimpleITK: The specified module could not be found.

```

I don’t know maybe the content of these files were changed while I was trying to repeat installation by modifying `setup.py` to discover the error and running it with command (as it is done in [External\_SimpleITK.cmake](https://github.com/Slicer/Slicer/blob/1efef1b35da0f95835c4f56def90629782cd492e/SuperBuild/External_SimpleITK.cmake#L197)):

```auto
cmake -P SimpleITK_install_step.cmake

```

Could you please take a look at my VS config:  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/0/3/0321569a383b7814d3df65ae501f6c40dbb0a449.png)

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [May 11, 2022, 3:06pm UTC](https://discourse.slicer.org/t/simpleitk-install-fails-on-windows/23373/4 "2022-05-11T15:06:52Z")

</div>

> [@keri](#):
>
> I don’t know maybe the content of these files were changed while I was trying to repeat installation by modifying `setup.py` to discover the error and running it with command (as it is done in [External\_SimpleITK.cmake](https://github.com/Slicer/Slicer/blob/1efef1b35da0f95835c4f56def90629782cd492e/SuperBuild/External_SimpleITK.cmake#L197)):

It is typically not worth spending time with manually altered builds. Instead, delete your entire build tree and restart the build from scratch. It is very important to not do any manual configuration in CMake but [configure and start your build using a .bat file](https://slicer.readthedocs.io/en/latest/developer_guide/build_instructions/windows.html#using-command-line-recommended) to make sure that you can anytime rebuild Slicer from scratch with a single click of a button.

> [@keri](#):
>
> `ImportError: DLL load failed while importing _SimpleITK: The specified module could not be found.`

This indicates that you had an error earlier during the build. You’ll do a clean build form scratch anyway, so preserve that build log and search for the first error. I usually do that by searching for `: err` in the full build log.

---

<div class="post-metadata">

**Author:** ![jamesobutler](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jamesobutler/32/7511_2.png) [@jamesobutler](https://discourse.slicer.org/u/jamesobutler)\
**Post date:** [May 11, 2022, 4:00pm UTC](https://discourse.slicer.org/t/simpleitk-install-fails-on-windows/23373/5 "2022-05-11T16:00:42Z")

</div>

This error appears very similar to what was discussed in [SimpleITK build error · Issue #6163 · Slicer/Slicer · GitHub](https://github.com/Slicer/Slicer/issues/6163).  
It was ultimately determined that it was a user’s use of some SimpleITK dependencies in the system path that caused the issue. See [SimpleITK build error · Issue #6163 · Slicer/Slicer · GitHub](https://github.com/Slicer/Slicer/issues/6163#issuecomment-1041467125).

---

<div class="post-metadata">

**Author:** ![keri](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/keri/32/11618_2.png) [@keri](https://discourse.slicer.org/u/keri)\
**Post date:** [May 11, 2022, 4:13pm UTC](https://discourse.slicer.org/t/simpleitk-install-fails-on-windows/23373/6 "2022-05-11T16:13:42Z")

</div>

Thank you for the information.

I’m rebuilding the app and I hope for the miracle 🙂  
If it doesn’t work I will investigate the root of the problem

---

<div class="post-metadata">

**Author:** ![keri](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/keri/32/11618_2.png) [@keri](https://discourse.slicer.org/u/keri)\
**Post date:** [May 11, 2022, 7:28pm UTC](https://discourse.slicer.org/t/simpleitk-install-fails-on-windows/23373/7 "2022-05-11T19:28:11Z")

</div>

@lassoan@jamesobutler I build `HDF5` as external project and I noticed that SimpleITK finds `HDF5` during cmake configuration time

I added HDF5 bin dir to `LibraryPaths` env var (in SimpleITK\_Env.cmake) and the problem was solved.

Thus in my SlicerCAT SimpleITK links to HDF5 while pure Slicer doesn’t have it (only within VTK and/or ITK pure SLicer has HDF5)

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [May 11, 2022, 8:21pm UTC](https://discourse.slicer.org/t/simpleitk-install-fails-on-windows/23373/8 "2022-05-11T20:21:54Z")

</div>

HDF5 is the library that most commonly breaks ITK build. It is always a huge pain. I’m not surprised that it broke your build, too.

> [@keri](#):
>
> I added HDF5 bin dir to `LibraryPaths` env var (in SimpleITK\_Env.cmake) and the problem was solved.

If this solves all your problems and this workaround is acceptable for you then it is good. I’m not sure if this is the cleanest solution, but if you submit a pull request then I’m sure that at some point @jcfr can have a look at it and merge it if there are no better ideas.

---

<div class="post-metadata">

**Author:** ![keri](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/keri/32/11618_2.png) [@keri](https://discourse.slicer.org/u/keri)\
**Post date:** [May 11, 2022, 8:53pm UTC](https://discourse.slicer.org/t/simpleitk-install-fails-on-windows/23373/9 "2022-05-11T20:53:45Z")

</div>

I agree with you

Sometimes to solve my issues I need to modify Slicer’s `External_smth.cmake`.  
In this case I prepare modified by me `External_smth.cmake` (in `SlicerCAT/CMake` dir) and during configuration time I copy this file to `slicersources-src/SuperBuild/External_smth.cmake` thus replacing Slicer’s original file:

```auto
configure_file(
    "${CMAKE_CURRENT_SOURCE_DIR}/CMake/External_VTK.cmake" 
    "${slicersources_SOURCE_DIR}/SuperBuild/External_VTK.cmake" COPYONLY
  )

```

I can’t do this know (I’m sorry) but in the future some of those dirty solutions should be implemented as a PRs (like with HDF5).

**Just in case some of my propositions (for the future):**

1. either build HDF5 as external project or add an opportunity to find HDF5 through HDF5\_ROOT (probably easier to handle HDF5 versions) var (requires to modify VTK and ITK ext projects). Modified [External\_VTK.cmake](https://github.com/tierra-colada/Colada/blob/master/CMake/External_VTK.cmake) and [External\_ITK.cmake](https://github.com/tierra-colada/Colada/blob/master/CMake/External_ITK.cmake)
2. ITK uses Eigen as third party libs. Add `mark_as_superbuild Eigen3_INCLUDE_DIR` to ITK ext project to link to Eigen. Because if some of ext proj also downloads Eigen and these Eigen libs are of different versions then you may face a problem when the compiled lib uses different Eigen libs in the same function for example. It is difficult to trace (I encountered that)
3. `sqlite` is very popular library and it should be built as shared library. It is pretty often that sqlite is a dependency of some project. For now only `python` uses sqlite. Just in case I prepared [shared sqlite project](https://github.com/tierra-colada/sqlite-amalgamation) (probably it could be done a little cleaner but it works) and the modified [External\_sqlite.cmake](https://github.com/tierra-colada/Colada/blob/master/CMake/External_sqlite.cmake). And probably `sqlite` should better be renamed to `SQLite3` as [CMake prefers](https://cmake.org/cmake/help/latest/module/FindSQLite3.html)

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [May 12, 2022, 3:36am UTC](https://discourse.slicer.org/t/simpleitk-install-fails-on-windows/23373/10 "2022-05-12T03:36:21Z")

</div>

> [@keri](#):
>
> either build HDF5 as external project or add an opportunity to find HDF5 through HDF5\_ROOT (probably easier to handle HDF5 versions) var (requires to modify VTK and ITK ext projects). Modified [External\_VTK.cmake](https://github.com/tierra-colada/Colada/blob/master/CMake/External_VTK.cmake) and [External\_ITK.cmake](https://github.com/tierra-colada/Colada/blob/master/CMake/External_ITK.cmake)

HDF5 is so messed up, build errors and ABI incompatibilites caused so much pain for ITK developers that they now just build it internally, using a custom prefix to isolate it from all external implementations.

Anyway, if you want to open this can of worm then you can put an `External_HDF5.cmake` into the `Superbuild` folder and set `Slicer_USE_SYSTEM_HDF5=ON`. It looks like Slicer automatically forwards this as `USE_SYSTEM_HDF5=ON` to all external projects.

> [@keri](#):
>
> ITK uses Eigen as third party libs. Add `mark_as_superbuild Eigen3_INCLUDE_DIR` to ITK ext project to link to Eigen. Because if some of ext proj also downloads Eigen and these Eigen libs are of different versions then you may face a problem when the compiled lib uses different Eigen libs in the same function for example. It is difficult to trace (I encountered that)

In general, well-behaving libraries, such ITK, VTK, etc. build their own dependencies (such as Eigen, SQLite, HDF5, …) and don’t leak them out on public APIs, or if they do then they use custom prefixes in symbol names and DLL names to avoid any interference with all the other instances of these common libraries.

> [@keri](#):
>
> `sqlite` is very popular library and it should be built as shared library. It is pretty often that sqlite is a dependency of some project. For now only `python` uses sqlite. Just in case I prepared [shared sqlite project](https://github.com/tierra-colada/sqlite-amalgamation) (probably it could be done a little cleaner but it works) and the modified [External\_sqlite.cmake](https://github.com/tierra-colada/Colada/blob/master/CMake/External_sqlite.cmake). And probably `sqlite` should better be renamed to `SQLite3` as [CMake prefers](https://cmake.org/cmake/help/latest/module/FindSQLite3.html)

A popular library typically cannot be built as a shared library due to API and ABI incompatibility issues. If it is a small library, such as SQLite, then the simplest is to just build it as a static library. If it is a huge and complex library, such as HDF5, then it may worth building it as a shared library - but then symbol names and shared library names require a custom prefix to ensure that many different versions can coexist.

---

<div class="post-metadata">

**Author:** ![keri](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/keri/32/11618_2.png) [@keri](https://discourse.slicer.org/u/keri)\
**Post date:** [May 12, 2022, 11:10am UTC](https://discourse.slicer.org/t/simpleitk-install-fails-on-windows/23373/11 "2022-05-12T11:10:43Z")

</div>

Thank you for the information

Regarding to the Slicer project I expect there most likely should not be ABI issues with generic libs like SQlite, HDF5 as we build everything at once.

In my case I needed to install PROJ and GDAL libs and they require SQlite. As I remember I couldn’t build them with static SQlite.

Current Slicer uses ITK v5.3rc03 wich uses latest Eigen 3.4 but before that ITK used Eigen 3.3 and I had external project Eigen 3.4  
I encountered a situation described above: in the same function I had two eigen versions worked differently 🙂

But I completely understand everything you said and probably in some cases SlicerCAT developers should be ready for things like that

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [May 12, 2022, 12:02pm UTC](https://discourse.slicer.org/t/simpleitk-install-fails-on-windows/23373/12 "2022-05-12T12:02:07Z")

</div>

> [@keri](#):
>
> probably in some cases SlicerCAT developers should be ready for things like that

Sometimes you cannot build everything yourself. For example, extensions can install Python wheels, or you may use some SDKs that contain pre-built binaries.

Sometimes your various software components require different versions of the same library, so you cannot build and use a single version everywhere.
