# import tensorflow from within Slicer python interactor causes crash

**URL:** <https://discourse.slicer.org/t/import-tensorflow-from-within-slicer-python-interactor-causes-crash/8054>\
**Category:** Development\
**Tags:** python\
**Created:** [August 16, 2019, 4:39am UTC](https://discourse.slicer.org/t/import-tensorflow-from-within-slicer-python-interactor-causes-crash/8054 "2019-08-16T04:39:15Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![gaoyi](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/gaoyi/32/4283_2.png) [@gaoyi](https://discourse.slicer.org/u/gaoyi)\
**Post date:** [August 16, 2019, 4:39am UTC](https://discourse.slicer.org/t/import-tensorflow-from-within-slicer-python-interactor-causes-crash/8054/1 "2019-08-16T04:39:15Z")

</div>

Hi All,

I build Slicer from trunk and pip\_install(“tensorflow”) from python interactor within Slicer (Ctrl + 3).  
Seems to be successful. Then I “import tensorflow”，but this crashes Slicer without detailed error message.

I tried this:  
./Slicer --launch …/python-install/bin/python  
Then in this python interpreter, I import tensorflow  
And things are fine (no crashing)

But within Slicer it crashes.

Could I have any hint on the direction I should look into?

Thank you!

yi

---

<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:** [August 16, 2019, 4:55am UTC](https://discourse.slicer.org/t/import-tensorflow-from-within-slicer-python-interactor-causes-crash/8054/2 "2019-08-16T04:55:30Z")

</div>

Importing tensorflow in Slicer GUI works fine on Windows (using a recent Slicer Preview Release - Slicer-4.11.0-2019-08-13).

What operating system and which Slicer version do you use? Do you have a stack trace of the crash? Have you pip-installed any other packages?

You may try to downgrade tensorflow or switch between GPU/CPU version.

---

<div class="post-metadata">

**Author:** ![gaoyi](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/gaoyi/32/4283_2.png) [@gaoyi](https://discourse.slicer.org/u/gaoyi)\
**Post date:** [August 16, 2019, 5:38am UTC](https://discourse.slicer.org/t/import-tensorflow-from-within-slicer-python-interactor-causes-crash/8054/3 "2019-08-16T05:38:12Z")

</div>

Hi Andras,

I’m using Linux Mint 19.1 with gcc 7.3 with nightly Slicer (20190816)

I didn’t pip install other packages except those trigger by tensorflow.

I tried both GPU (tensorflow-gpu) and CPU versions and both crashes.

I don’t have crash trace yet. It just says :  
./SlicerApp-real] exit abnormally - Report the problem.

How could I get the trace info?

Thanks!  
yi

---

<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:** [August 16, 2019, 12:25pm UTC](https://discourse.slicer.org/t/import-tensorflow-from-within-slicer-python-interactor-causes-crash/8054/4 "2019-08-16T12:25:48Z")

</div>

I don’t know how to debug this on linux, hopefully others can help.

Alternatively, you can run your Python script as a CLI module. See example [here](https://github.com/lassoan/SlicerPythonCLIExample).

---

<div class="post-metadata">

**Author:** ![gaoyi](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/gaoyi/32/4283_2.png) [@gaoyi](https://discourse.slicer.org/u/gaoyi)\
**Post date:** [August 16, 2019, 12:31pm UTC](https://discourse.slicer.org/t/import-tensorflow-from-within-slicer-python-interactor-causes-crash/8054/5 "2019-08-16T12:31:00Z")

</div>

Thank you Andras!

I’ll investigate the CLI python approach and update with you.

Best,  
yi

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [August 16, 2019, 3:35pm UTC](https://discourse.slicer.org/t/import-tensorflow-from-within-slicer-python-interactor-causes-crash/8054/6 "2019-08-16T15:35:44Z")

</div>

> [@gaoyi](#):
>
> I don’t have crash trace yet. It just says :  
> ./SlicerApp-real] exit abnormally - Report the problem.

You could also generate a core dump and than open it with ddd (or gdb). While there are no debug info available within Release build, it should still provide some useful information.

See [Documentation/Nightly/Developers/Tutorials/Debug Instructions - Slicer Wiki](https://www.slicer.org/wiki/Documentation/Nightly/Developers/Tutorials/Debug_Instructions#Analyze_a_segmentation_fault)

---

<div class="post-metadata">

**Author:** ![gaoyi](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/gaoyi/32/4283_2.png) [@gaoyi](https://discourse.slicer.org/u/gaoyi)\
**Post date:** [August 17, 2019, 12:12am UTC](https://discourse.slicer.org/t/import-tensorflow-from-within-slicer-python-interactor-causes-crash/8054/7 "2019-08-17T00:12:43Z")

</div>

Thanks Jc,

Will do this and report back soon.

Best,  
yi

---

<div class="post-metadata">

**Author:** ![gaoyi.cn](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/gaoyi.cn/32/1422_2.png) [@gaoyi.cn](https://discourse.slicer.org/u/gaoyi.cn)\
**Post date:** [October 19, 2019, 3:13am UTC](https://discourse.slicer.org/t/import-tensorflow-from-within-slicer-python-interactor-causes-crash/8054/8 "2019-10-19T03:13:17Z")

</div>

Hi Andras,

In trying the python CLI, how could i assign the python environment I want Slicer to run my pythonCLI with? (Say my python exe is in /opt/anacondaGPU/bin/python)

Thanks for the advice!

Best,  
yi
