UsageError: Line magic function `%tensorflow_version` not found

sof*_*x55 16 python tensorflow jupyter-notebook

I've got TensorFlow installed on my machine however I'm keep getting the error: UsageError: Line magic function `%tensorflow_version` not found.

Any ideas as to why this is? The code I ran is below (Jupyter Notebook)

%tensorflow_version 1.x
import tensorflow as tf
print(tf.__version__)
Run Code Online (Sandbox Code Playgroud)

Jam*_*mes 21

Jupyter notebook comes with a set of magic functions, but %tensorflow_version is not one of them. The magic command

%tensorflow_version X.X
Run Code Online (Sandbox Code Playgroud)

is only available in Google Colab notebooks, not Jupyter notebooks.


Rya*_*thm 8

这段代码

%tensorflow_version 1.x
Run Code Online (Sandbox Code Playgroud)

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

命令行,安装特定版本:

pip install tensorflow==1.15.0
Run Code Online (Sandbox Code Playgroud)

或在您的 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
Run Code Online (Sandbox Code Playgroud)