为什么我会收到错误“ModuleNotFoundError: No module named 'tensorflow.python.client'"?即使在安装 tensorflow 之后,在 Pycharm 中? [英] Why do I get the error "ModuleNotFoundError: No module named 'tensorflow.python.client' " in Pycharm even after installing tensorflow?

查看:87
本文介绍了为什么我会收到错误“ModuleNotFoundError: No module named 'tensorflow.python.client'"?即使在安装 tensorflow 之后,在 Pycharm 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在 Mac 上通过终端使用 pip 安装了 tensorflow,我正在尝试在 Pycharm 中使用它.但出于某种原因,我不断收到此错误:

ModuleNotFoundError:没有名为tensorflow.python.client"的模块

我正在运行此代码:

# TensorFlow 和 tf.keras将张量流导入为 tf从 tensorflow 导入 keras# 辅助库将 numpy 导入为 np导入 matplotlib.pyplot 作为 plt打印(tf.__version__)

我已经查看了此页面的基本安装(

I have installed tensorflow using pip through Terminal on my Mac and I am trying to use it in Pycharm. But for some reason, I keep getting this error:

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

I am running this code:

# 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__)

I have looked at this page for basic installation (https://www.tensorflow.org/install/pip) and after following the instructions in Terminal I can run this code:

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

And this is the corresponding output:

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)

Hopefully, I have provided enough details to sort the issue, I am trying to run basic ML using tensorflow :)

解决方案

Pycharm uses a virtual environment for each of the projects. If you go under settings -> python interpreter (see image), you can check which one you're running. I expect it's installed under a different environment and you'll be able to switch it to the correct one.

这篇关于为什么我会收到错误“ModuleNotFoundError: No module named 'tensorflow.python.client'"?即使在安装 tensorflow 之后,在 Pycharm 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆