【问题标题】:Problem with tensorflow and matplotlib packages when attempting MNIST dataset尝试 MNIST 数据集时出现 tensorflow 和 matplotlib 包的问题
【发布时间】:2020-04-24 04:52:48
【问题描述】:

我正在尝试使用 tensorflow 做 MNIST 数据集作为练习,但我遇到了一些包问题。我正在使用 Pycharm 2019.3.1。 这是我的代码:

import tensorflow as tf
import matplotlib.pyplot as plt

(x_train, y_train), (x_test, y_test) = tf.keras.datasets.mnist.load_data()
image_index = 7777
print(y_train(image_index))
plt.inshow(x_train(image_index))

我收到“没有名为 tensorflow 的模块”和“没有名为 matplotlib 的模块”错误。

【问题讨论】:

  • 错误提示你运行代码的环境中没有安装tensorflow和matplotlib。
  • 请检查这些包是否安装在File - Settings - Project - Project Interpreter指定的Python解释器上

标签: python tensorflow matplotlib pycharm


【解决方案1】:

以上错误说明你的系统中没有安装tensorflow和matplotlib库。你可以创建一个虚拟环境或者conda环境,然后激活环境,安装上面的库,在新建的虚拟环境或者conda环境中运行上面的python程序。

【讨论】:

  • 在我保存文件的目录中编写任何代码之前,我确实安装了这两个包。无论如何我都必须使用 conda env 吗?
  • 如果您在 python 中使用不同的库,则非常需要虚拟环境或 conda 环境。如果您已正确安装 tf 和 plt,则应该没有任何问题。但我仍然建议您使用 virtual 或 conda env。这可能会帮助你docs.conda.io/projects/conda/en/latest/user-guide/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-04-10
  • 1970-01-01
  • 1970-01-01
  • 2021-06-13
  • 2023-03-13
  • 1970-01-01
相关资源
最近更新 更多