Skip to content

Instantly share code, notes, and snippets.

@daj
Last active August 1, 2018 22:51
Show Gist options
  • Save daj/6d920efcea19fda927e4b69b75643399 to your computer and use it in GitHub Desktop.
Save daj/6d920efcea19fda927e4b69b75643399 to your computer and use it in GitHub Desktop.
Check Python can import TensorFlow dependencies
# This script assumes you are running from Terminal / command line
python
import tensorflow as tf
hello = tf.constant('Hello from TensorFlow. Everything seems to be working!')
sess = tf.Session()
print(sess.run(hello))
exit()
@daj
Copy link
Author

daj commented Feb 20, 2017

Here's an example what you'll see if your TensorFlow dependencies are not setup correctly:

$ python
Python 2.7.6 (default, Feb 18 2014, 10:07:05) 
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 
>>> import tensorflow as tf
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "tensorflow/__init__.py", line 24, in <module>
    from tensorflow.python import *
  File "tensorflow/python/__init__.py", line 72, in <module>
    raise ImportError(msg)
ImportError: Traceback (most recent call last):
  File "tensorflow/python/__init__.py", line 61, in <module>
    from tensorflow.python import pywrap_tensorflow
ImportError: cannot import name pywrap_tensorflow


Failed to load the native TensorFlow runtime.

See https://github.com/tensorflow/tensorflow/blob/master/tensorflow/g3doc/get_started/os_setup.md#import_error

for some common reasons and solutions.  Include the entire stack trace
above this error message when asking for help.
>>> hello = tf.constant('Hello, TensorFlow!')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'tf' is not defined
>>> sess = tf.Session()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'tf' is not defined
>>> print(sess.run(hello))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'sess' is not defined
>>> 
>>> exit()

@noumanschaudhry
Copy link

the script in your first post worked fine without any errors.

but i am facing this when I run my code :

anaconda3/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py in ()
3 from future import print_function
4
----> 5 import tensorflow as tf
6 from tensorflow.python.framework import ops as tf_ops
7 from tensorflow.python.training import moving_averages

anaconda3/lib/python3.6/site-packages/tensorflow/init.py in ()
598 # resolution to succeed.
599 # pylint: disable=undefined-variable
--> 600 del python
601 del core
602 # pylint: enable=undefined-variable

NameError: name 'python' is not defined

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment