I have just built Tensorflow r1.12 from source in Ubuntu 16.04. The installation is successful.
When I run a certain script in Spyder at the 1st time, everything flows smoothly. However, when I continue to run another script, following errors occur (which didn't happen previously):
File "/home/haohua/tf_env/lib/python3.6/site-packages/tensorflow/ init .py", line 24, in from tensorflow.python import pywrap_tensorflow # pylint: disable=unused-import
File "/home/haohua/tf_env/lib/python3.6/site-packages/tensorflow/python/ init .py", line 70, in from tensorflow.python.framework.framework_lib import * # pylint: disable=redefined-builtin
File "/home/haohua/tf_env/lib/python3.6/site-packages/tensorflow/python/framework/framework_lib.py", line 30, in from tensorflow.python.framework.sparse_tensor import SparseTensor
File "/home/haohua/tf_env/lib/python3.6/site-packages/tensorflow/python/framework/sparse_tensor.py", line 248, in pywrap_tensorflow.RegisterType("SparseTensorValue", SparseTensorValue)
TypeError: Type already registered for SparseTensorValue
The temporary solution to avoid such TypeError is to restart the kernel.
But I don't want to restart kernel at every single step of running a script. Thus, I would like to ask for a critical solution for such kind of issue. Thank you in advance.
( 此处为Spyder维护人员 )此错误已在2019年2月发布的Spyder 3.3.3中修复。
Get rid of the import statement:
import tensorflow as tf
Seems to work after that... it's kinda janky
import tensorflow as tf
node1 = tf.constant(3.0,tf.float32)
node2 = tf.constant(4.0)
sess = tf.Session()
print(sess.run([node1,node2]))
sess.close()
When you run this code the first time it will show the output, but when you run it for the second time it will show the error. For that, you have to select the whole program except import tensorflow as tf
and run in
run in current cell mode
it will work and it will show the output;
Otherwise, restart your kernel it will work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.