首页 > 解决方案 > 通过安装了 python 的终端在 macOS 上运行 Keras?

问题描述

当我在 macOS 上的终端中键入命令“从 tensorflow 导入 keras”时,我得到

“来自:无法读取 /var/mail/tensorflow”

标签: python

解决方案


您不能直接将 Python 代码写入 CLI。这只在某种程度上接受shell命令。

您可以:

  1. 从 CLI 启动 Python 解释器并直接使用它,例如
$ python3
Python 3.9.4 (default, Apr  5 2021, 01:50:46)
[Clang 12.0.0 (clang-1200.0.32.29)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from tensorflow import keras
  1. 或将所有代码写入文本文件并将其命名为my_first_script.py,例如
#!/usr/bin/env python3

import tensorflow as tf
from tensorflow import keras

# the rest of your code

然后你用python运行它,例如

$ python my_first_script.py

在这里查看本教程


推荐阅读