# Error 'tf' not found

**URL:** <https://discourse.slicer.org/t/error-tf-not-found/10442>\
**Category:** Support\
**Created:** [February 26, 2020, 2:44pm UTC](https://discourse.slicer.org/t/error-tf-not-found/10442 "2020-02-26T14:44:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![tkt8](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/tkt8/32/5758_2.png) [@tkt8](https://discourse.slicer.org/u/tkt8)\
**Post date:** [February 26, 2020, 2:44pm UTC](https://discourse.slicer.org/t/error-tf-not-found/10442/1 "2020-02-26T14:44:54Z")

</div>

I have installed tensorflow in the night build. And I am importing tensorflow as tf in my code. But I get an error stating “tf” not found. This is solved by importing tensorflow as tf in the python interpreter. Can you please tell me what I am doing wrong?

Thanks,  
Tanvi

---

<div class="post-metadata">

**Author:** ![ungi](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ungi/32/78573_2.png) [@ungi](https://discourse.slicer.org/u/ungi)\
**Post date:** [February 26, 2020, 5:17pm UTC](https://discourse.slicer.org/t/error-tf-not-found/10442/2 "2020-02-26T17:17:22Z")

</div>

Did you install TensorFlow with this command in a recent version of Slicer?  
`pip_install('tensorflow')`  
Then, you should be able to import and use TensorFlow.  
We experienced an error recently on Windows, and the solution was to install Visual Studio on the same computer. Apparently, the Windows version of TensorFlow requires something from Visual Studio that it doesn’t package automatically.

---

<div class="post-metadata">

**Author:** ![tkt8](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/tkt8/32/5758_2.png) [@tkt8](https://discourse.slicer.org/u/tkt8)\
**Post date:** [February 26, 2020, 5:25pm UTC](https://discourse.slicer.org/t/error-tf-not-found/10442/3 "2020-02-26T17:25:09Z")

</div>

I had installed tensorflow using slicer.util.pip\_install(“tensorflow”). And i am using a Linux machine.  
I tried using the pip\_install command but the same issue is there where I still have to manually import tensorflow in the python interpreter rather than it automatically being done in \*.py file

---

<div class="post-metadata">

**Author:** ![ungi](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ungi/32/78573_2.png) [@ungi](https://discourse.slicer.org/u/ungi)\
**Post date:** [February 26, 2020, 5:53pm UTC](https://discourse.slicer.org/t/error-tf-not-found/10442/4 "2020-02-26T17:53:28Z")

</div>

If your .py file is a module for 3D Slicer, and you have installed TensorFlow with the slicer.util.pip\_install() command, then you can just add import tensorflow at the beginning of your .py file, and that should work.

---

<div class="post-metadata">

**Author:** ![tkt8](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/tkt8/32/5758_2.png) [@tkt8](https://discourse.slicer.org/u/tkt8)\
**Post date:** [February 28, 2020, 7:34pm UTC](https://discourse.slicer.org/t/error-tf-not-found/10442/5 "2020-02-28T19:34:30Z")

</div>

Traceback (most recent call last):  
File “/home/tpk11/Slicer\_MimickNet/MimickNet/MimickNet.py”, line 118, in onApplyButton  
logic.run(self.inputSelector.currentNode(),self.modelPathEdit.currentPath)  
File “/home/tpk11/Slicer\_MimickNet/MimickNet/MimickNet.py”, line 168, in run  
model = tf.keras.models.load\_model(path)  
File “/scratch/tpk11/Slicer/lib/Python/lib/python3.6/site-packages/tensorflow\_core/python/keras/saving/save.py”, line 146, in load\_model  
return hdf5\_format.load\_model\_from\_hdf5(filepath, custom\_objects, compile)  
File “/scratch/tpk11/Slicer/lib/Python/lib/python3.6/site-packages/tensorflow\_core/python/keras/saving/hdf5\_format.py”, line 168, in load\_model\_from\_hdf5  
custom\_objects=custom\_objects)  
File “/scratch/tpk11/Slicer/lib/Python/lib/python3.6/site-packages/tensorflow\_core/python/keras/saving/model\_config.py”, line 55, in model\_from\_config  
return deserialize(config, custom\_objects=custom\_objects)  
File “/scratch/tpk11/Slicer/lib/Python/lib/python3.6/site-packages/tensorflow\_core/python/keras/layers/serialization.py”, line 106, in deserialize  
printable\_module\_name=‘layer’)  
File “/scratch/tpk11/Slicer/lib/Python/lib/python3.6/site-packages/tensorflow\_core/python/keras/utils/generic\_utils.py”, line 303, in deserialize\_keras\_object  
list(custom\_objects.items())))  
File “/scratch/tpk11/Slicer/lib/Python/lib/python3.6/site-packages/tensorflow\_core/python/keras/engine/network.py”, line 937, in from\_config  
config, custom\_objects)  
File “/scratch/tpk11/Slicer/lib/Python/lib/python3.6/site-packages/tensorflow\_core/python/keras/engine/network.py”, line 1903, in reconstruct\_from\_config  
process\_node(layer, node\_data)  
File “/scratch/tpk11/Slicer/lib/Python/lib/python3.6/site-packages/tensorflow\_core/python/keras/engine/network.py”, line 1851, in process\_node  
output\_tensors = layer(input\_tensors, \*\*kwargs)  
File “/scratch/tpk11/Slicer/lib/Python/lib/python3.6/site-packages/tensorflow\_core/python/keras/engine/base\_layer.py”, line 773, in **call**  
outputs = call\_fn(cast\_inputs, \*args, \*\*kwargs)  
File “/scratch/tpk11/Slicer/lib/Python/lib/python3.6/site-packages/tensorflow\_core/python/keras/layers/core.py”, line 846, in call  
result = self.function(inputs, \*\*kwargs)  
File “”, line 2, in custom\_pad  
NameError: name ‘tf’ is not defined

This is the error i get. Tensorflow is being imported in the module .py file
