ModuleNotFoundError:没有名为“ tensorflow.compiler”的模块

时间:2018-08-18 13:44:35

标签: python python-3.x tensorflow google-cloud-tpu

import numpy as np

a = np.array([1,2,3,4,5])
b = np.array([2,3,4,5,6])
c = np.array([5,6,7,8,9])
a,b = a[c>6],b[c>6]
print (a,b)

当我运行以下代码时,发生了上述错误: env:windows10 + jupyter notebook + tensorflow1.9 + python3.6

~\AppData\Roaming\Python\Python36\site-packages\tensorflow\contrib\tpu\python\tpu\tpu_estimator.py in <module>()
     38 from tensorflow.contrib.tpu.python.tpu import tpu_config
     39 from tensorflow.contrib.tpu.python.tpu import tpu_context
---> 40 from tensorflow.contrib.tpu.python.tpu import tpu_feed
     41 from tensorflow.contrib.tpu.python.tpu import training_loop
     42 from tensorflow.contrib.tpu.python.tpu import util as util_lib

~\AppData\Roaming\Python\Python36\site-packages\tensorflow\contrib\tpu\python\tpu\tpu_feed.py in <module>()
     26 from six.moves import xrange  # pylint: disable=redefined-builtin
     27 
---> 28 from tensorflow.compiler.xla.experimental.xla_sharding import xla_sharding
     29 from tensorflow.compiler.xla.python_api import xla_shape
     30 from tensorflow.contrib.tpu.python.ops import tpu_ops

ModuleNotFoundError: No module named 'tensorflow.compiler'

2 个答案:

答案 0 :(得分:0)

我在Python TPU(ctpu)计算机上使用Python 3运行了您的示例,定义了x并初始化了全局变量,如下所示:

sess = tf.Session()
sess.run(tf.global_variables_initializer())
x = tf.ones(shape=[24*24*3*50], dtype=tf.float32)
x_image = tf.reshape(x, [-1,24,24,3])
h_conv1 = tf.contrib.layers.conv2d(x_image, 64,5,1, "SAME",
                                   activation_fn=tf.nn.relu)
sess.run(h_conv1)

它正常工作。

答案 1 :(得分:0)

如果Tensorflow的安装不完整(例如,“ pip install tensorflow”已中断),则会发生此错误。