# Using SlicerElastix binaries in the terminal

**URL:** <https://discourse.slicer.org/t/using-slicerelastix-binaries-in-the-terminal/5017>\
**Category:** Support\
**Created:** [December 8, 2018, 2:54pm UTC](https://discourse.slicer.org/t/using-slicerelastix-binaries-in-the-terminal/5017 "2018-12-08T14:54:35Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![brhoom](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/brhoom/32/1228_2.png) [@brhoom](https://discourse.slicer.org/u/brhoom)\
**Post date:** [December 8, 2018, 2:54pm UTC](https://discourse.slicer.org/t/using-slicerelastix-binaries-in-the-terminal/5017/1 "2018-12-08T14:54:35Z")

</div>

Operating system: Ubuntu  
Slicer version: 4.10  
Expected behavior: work  
Actual behavior: does not work

Based on [this](https://discourse.slicer.org/t/extension-contribution-checklist/4975/2) and [this](https://discourse.slicer.org/t/vissim-cochlea-tools-extension-is-now-public/4122/15) discussions, I tried to use:

```
  .config/NA-MIC/Extensions-27501/SlicerElastix/lib/Slicer-4.10/elastix  

```

but I got this error:

```
  .config/NA-MIC/Extensions-27501/SlicerElastix/lib/Slicer-4.10/elastix: error while loading shared libraries: libi2d.so.13: cannot open shared object file: No such file or directory

```

I know I can just call some function but I will have to modify many things in my code. Is there another way to call it from the terminal?

---

<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:** [December 8, 2018, 3:14pm UTC](https://discourse.slicer.org/t/using-slicerelastix-binaries-in-the-terminal/5017/2 "2018-12-08T15:14:26Z")

</div>

Can you start Elastix bundled with the latest nightly version? Does Elastix work with the latest nightly build when launched useing “General registration (Elastix)” module? Next steps depend on the answer to these questions.

---

<div class="post-metadata">

**Author:** ![brhoom](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/brhoom/32/1228_2.png) [@brhoom](https://discourse.slicer.org/u/brhoom)\
**Post date:** [December 8, 2018, 3:43pm UTC](https://discourse.slicer.org/t/using-slicerelastix-binaries-in-the-terminal/5017/3 "2018-12-08T15:43:24Z")

</div>

I got same error above using nightly build (just downloaded it) . Elastix works in Slicer but does not work from the terminal. It would be nice if it runs from the terminal even using Slicer --launch option.

---

<div class="post-metadata">

**Author:** ![brhoom](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/brhoom/32/1228_2.png) [@brhoom](https://discourse.slicer.org/u/brhoom)\
**Post date:** [December 8, 2018, 6:30pm UTC](https://discourse.slicer.org/t/using-slicerelastix-binaries-in-the-terminal/5017/4 "2018-12-08T18:30:12Z")

</div>

I did more testing, here is the result

Using nightly build:

- I can run elastix in the python interactor, I guess it should work also in the plugin.
- I can not run elastix in Ubuntu terminal but I think this should not be a problem as the above work.

Using 4.10:

- I can not run elastix in Ubuntu terminal
- In Slicer, the plugin itself is not stable, sometimes the testing works and sometimes not.

---

<div class="post-metadata">

**Author:** ![brhoom](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/brhoom/32/1228_2.png) [@brhoom](https://discourse.slicer.org/u/brhoom)\
**Post date:** [December 8, 2018, 6:44pm UTC](https://discourse.slicer.org/t/using-slicerelastix-binaries-in-the-terminal/5017/5 "2018-12-08T18:44:13Z")

</div>

I did more testing. SlicerElastix does not work after I run SliacerCochlea. If I restart Slicer and run SlicerElastix, it works.

What could be the problem in SlicerCochlea code???

---

<div class="post-metadata">

**Author:** ![brhoom](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/brhoom/32/1228_2.png) [@brhoom](https://discourse.slicer.org/u/brhoom)\
**Post date:** [December 8, 2018, 6:47pm UTC](https://discourse.slicer.org/t/using-slicerelastix-binaries-in-the-terminal/5017/6 "2018-12-08T18:47:24Z")

</div>

Problem solved! I disabled these lines

```
#os.environ['LD_LIBRARY_PATH'] = self.vissimPath + "/sw/elastix-4.9.0/lib"
#os.environ['LD_LIBRARY_PATH'] = self.vissimPath + "/sw/elastix-4.9.0/lib"

```

Everything works now in Slicer. Only the terminal problem to be solved.

---

<div class="post-metadata">

**Author:** ![brhoom](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/brhoom/32/1228_2.png) [@brhoom](https://discourse.slicer.org/u/brhoom)\
**Post date:** [December 8, 2018, 6:52pm UTC](https://discourse.slicer.org/t/using-slicerelastix-binaries-in-the-terminal/5017/7 "2018-12-08T18:52:03Z")

</div>

Since some plugins affect other plugins negatively, something should be done to avoid this as this makes it difficult to find the source of the problem if it is from another extension.

---

<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:** [December 8, 2018, 7:07pm UTC](https://discourse.slicer.org/t/using-slicerelastix-binaries-in-the-terminal/5017/8 "2018-12-08T19:07:38Z")

</div>

I don’t think there are any issues or limitations here, you just need to clearly distinguish between binaries built by Slicer factory machines (and included in extensions); and third-party binaries present on the system. Third-party binaries can be included in extensions, but this should be avoided.

**Running executables bundled in a Slicer extension:**

There is no interference between extensions if you let Slicer factory build all libraries (you must not bundle binaries created elsewhere). If there are libraries or executable used by multiple extensions (for example Elastix is used by several extensions) then you need to make sure that one extension builds the shared library and all other extensions depend on that. See how [SequenceRegistration extension uses SlicerElastix](https://github.com/moselhy/SlicerSequenceRegistration/blob/df60af069abb19397f8036c8d2d6d9c1816d8152/SequenceRegistration/SequenceRegistration.py#L557-L562) for an example.

In the very rare case that different extensions use must incompatible versions of the same libraries, you can statically link the old version of the library to the extension that requires the old library version. We have 100+ extensions and I think this happened only once.

**Running third-party executables or scripts installed on the system (not bundled with Slicer):**

If you want to start third-party programs (executables, Python scripts, etc.) from Slicer, then you usually need to use startup environment as described [here](https://www.slicer.org/wiki/Documentation/Nightly/Developers/Python_scripting#How_to_run_Python_script_using_a_non-Slicer_Python_environment).

---

<div class="post-metadata">

**Author:** ![brhoom](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/brhoom/32/1228_2.png) [@brhoom](https://discourse.slicer.org/u/brhoom)\
**Post date:** [December 8, 2018, 7:22pm UTC](https://discourse.slicer.org/t/using-slicerelastix-binaries-in-the-terminal/5017/9 "2018-12-08T19:22:30Z")

</div>

Thanks for the detailed info. I don’t understand the last part. Could you please provide an example of how to run the elastix binary in the terminal (not in python).

---

<div class="post-metadata">

**Author:** ![thewtex](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/thewtex/32/32_2.png) [@thewtex](https://discourse.slicer.org/u/thewtex)\
**Post date:** [December 8, 2018, 8:01pm UTC](https://discourse.slicer.org/t/using-slicerelastix-binaries-in-the-terminal/5017/10 "2018-12-08T20:01:19Z")

</div>

Binaries to run elastix in the terminal can be [downloaded from the elastix GitHub release page](https://github.com/SuperElastix/elastix/releases).

---

<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:** [December 8, 2018, 8:15pm UTC](https://discourse.slicer.org/t/using-slicerelastix-binaries-in-the-terminal/5017/11 "2018-12-08T20:15:19Z")

</div>

> [@brhoom](#):
>
> run the elastix binary in the terminal (not in python)

Would you run it manually by typing commands on the terminal? Or using a bash script? Don’t you want to use it from your Python scripted module?

Anyway, you can use third-party libraries on your system as @thewtex suggested above (completely independently from Slicer), or run any Slicer executables using the launcher, for example:

```
"c:\Program Files\Slicer 4.10.0\Slicer.exe" --launch c:\Users\andra\AppData\Roaming\NA-MIC\Extensions-27501\SlicerElastix\lib\Slicer-4.10\elastix.exe --help >>output.txt

```

---

<div class="post-metadata">

**Author:** ![brhoom](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/brhoom/32/1228_2.png) [@brhoom](https://discourse.slicer.org/u/brhoom)\
**Post date:** [December 8, 2018, 11:39pm UTC](https://discourse.slicer.org/t/using-slicerelastix-binaries-in-the-terminal/5017/12 "2018-12-08T23:39:48Z")

</div>

> Binaries to run elastix in the terminal can be

I needed the one from Slicer to debug my module.

> or run any Slicer executables using the launcher  
> Slicer --launch executable

That is exactly what I needed, thanks a lot.
