Jupyter使用

在cmd中使用命令运行

jupyter notebook

打开jupyter notebook网页页面。

Jupyter使用_第1张图片

按图片中的步骤进行操作建立新的运行文件。你可以在点击如下图的地方修改你的文件名称。

import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
a = tf.random_normal([2,30])
sess = tf.Session()
out = sess.run(a)
x,y = out
plt.scatter(x, y)
plt.show()

 之后你可以拿一段小代码进行测试。

shift+enter或者点击运行(run)运行测试。这时候你会发现会提示错误如下

ModuleNotFoundError: No module named 'tensorflow'

由于我是通过pip 安装 jupyternotebook,区别于anaconda安装,我们可以在此页面下载安装包,用如下命令安装后再进行运行:

!pip install tensorflow -i https://pypi.doubanio.com/simple/

 解决了以上问题后,又产生了新的问题:

 jupyter module 'tensorflow' has no attribute 'random_normal'

原因是因为:我使用的是tf2,最新一版的random_normal方法已经换为:random.normal

我们可以将下面这段代码来替换import tensorflow as tf

import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()

 这个可以解决产生 jupyter module 'tensorflow' has no attribute 'random_normal'大部分问题。

 运行代码成功就会显示如下图:Jupyter使用_第2张图片

 

你可能感兴趣的:(jupyter,python,人工智能)