为什么即使在安装了tensorflow之后,在Pycharm中仍然出现错误“ ModuleNotFoundError:没有名为'tensorflow.python.client'的模块”?

时间:2020-07-15 10:15:21

标签: python tensorflow

我已经通过Mac上的Terminal通过pip安装了tensorflow,我正在尝试在Pycharm中使用它。但是由于某些原因,我一直收到此错误:

ModuleNotFoundError: No module named 'tensorflow.python.client'

我正在运行以下代码:

# TensorFlow and tf.keras
import tensorflow as tf
from tensorflow import keras

# Helper libraries
import numpy as np
import matplotlib.pyplot as plt

print(tf.__version__)

我已经在此页面上进行了基本安装(https://www.tensorflow.org/install/pip),并且按照终端中的说明进行操作之后,我可以运行以下代码:

python3 -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))"

这是相应的输出:

2020-07-15 10:57:44.397351: I tensorflow/core/platform/cpu_feature_guard.cc:143] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2020-07-15 10:57:44.436720: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x12aa14200 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-07-15 10:57:44.436757: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version 
tf.Tensor(-627.3514, shape=(), dtype=float32)

希望我提供了足够的细节来解决问题,我正在尝试使用tensorflow运行基本的ML:)

1 个答案:

答案 0 :(得分:1)

Pycharm对每个项目都使用虚拟环境。如果进入设置-> python解释器(参见图片),则可以检查正在运行的是哪个。我希望它安装在其他环境下,您可以将其切换到正确的环境。

Under settings, select interpreter

相关问题