使用错误:找不到行魔法函数`%tensorflow_version`。

23

我已经在我的设备上安装了TensorFlow,但是我一直收到这个错误信息:UsageError: Line magic function `%tensorflow_version` not found.

你有什么想法为什么会出现这种情况?我运行的代码如下(在Jupyter Notebook中)

%tensorflow_version 1.x
import tensorflow as tf
print(tf.__version__)
2个回答

32

Jupyter notebook带有一组魔术函数,但%tensorflow_version不是其中之一。该魔法命令


%tensorflow_version X.X

此功能只在Google Colab笔记本中可用,而非Jupyter笔记本。


10

这段代码

%tensorflow_version 1.x

...是Google Colab中的一个“魔法”命令(“魔法咒语”),它指示Colab环境使用最新稳定版本的Tensorflow 1。如果您想让代码在自己的Jupyter笔记本上运行,您需要在本地安装Tensorflow。有几种方法:

命令行,安装特定版本:

pip install tensorflow==1.15.0

或者在你的 Jupyter 笔记本中:

import sys 
!{sys.executable} -m pip install tensorflow==1.15.0
# !{sys.executable} -m pip install --user tensorflow==1.15.0. # you may need '--user' based on your environment

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接