UsageError:找不到线魔术函数`%tensorflow_version`

问题描述 投票:4回答:2

我的机器上已经安装了TensorFlow,但是我不断收到错误:UsageError: Line magic function `%tensorflow_version` not found.

关于这是为什么的任何想法?我运行的代码如下(Jupyter Notebook)

%tensorflow_version 1.x
import tensorflow as tf
print(tf.__version__)
python tensorflow jupyter-notebook
2个回答
4
投票

Jupyter笔记本电脑具有一组魔术功能,但是%tensorflow_version不是其中之一。魔术命令

%tensorflow_version X.X

仅在Google Colab笔记本中可用,在Jupyter笔记本中不可用。


0
投票

此代码

%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

0
投票

尝试:#%tensorflow_version仅存在于Colab中。%tensorflow_version 2.x例外:通过

https://www.tensorflow.org/tensorboard/migrate

我安装了python 3.7,并且print(tf .__ version__)命令不起作用

© www.soinside.com 2019 - 2024. All rights reserved.