机器学习-JupyterNotebook使用中的错误集锦

人工智能56

目录

系统Windows10,Python3.9

1.改变jupyter的文件存储路径

2.调用module中的错误

(1)module 'numpy' has no attribute 'version'

(2)TensorFlow

1)module 'numpy' has no attribute 'version'

2)The Session graph is empty. Add operations to the graph before calling run().

系统Windows10,Python3.9

1.改变jupyter的文件存储路径

(1)通过Windows进入

WIN+R打开运行,输入cmd-输入 jupyter notebook --generate-config显示新生成的jupyter_notebook_config.py文件的用户目录,用 Notepad++或者记事本打开该文件,通过 Ctrl+F调出查找窗口,输入 The directory to use for notebooks,点击查找下一个,c.NotebookApp.notebook_dir =' E:\jupyter'(改为新的存储路径,我的是 E:\jupyter),

注意:一定要把前面的#去掉

(2)通过快捷方式进入

在开始界面找到jupyter notebook的快捷方式,右键-更多-打开文件所在位置-找到jupyter notebook,右键-属性-目标中.py之后的后缀去掉,换成 "E:\jupyter"(新的存储路径),如下图所示:

机器学习-JupyterNotebook使用中的错误集锦

2.调用module中的错误

(1)module 'numpy' has no attribute 'version'

import numpy

numpy.version(version前后是_ _,两个连着的下划线,不是一个,亲测有用!!!)

我出这个错误看了好多相关回帖,解决方案包括:numpy的卸载重新安装;安装TensorFlow,如果和我一样是小白刚刚下载,拜托先看看前后的下划线长不长吧呜呜~

(2)TensorFlow

tensorflow2.0后的版本一些语句命令有变化

1)module 'numpy' has no attribute 'version'

输入tf.Session报错 module 'numpy' has no attribute 'version',是版本原因,将语句改为 tf.compat.v1.Session()

2) The Session graph is empty. Add operations to the graph before calling run().

解决方案:加入tf.compat.v1.disable_eager_execution()该语句

如下示例:

import tensorflow as tf
tf.compat.v1.disable_eager_execution()
hello=tf.constant('Hello,tensorflow')
sess= tf.compat.v1.Session()
print(sess.run(hello))

(作为一个学习笔记,帮助自己后面学习和巩固,也希望大家不要和我一样因为一个小问题纠结好几天了)

Original: https://blog.csdn.net/weixin_47685937/article/details/124614734
Author: ISMyrna
Title: 机器学习-JupyterNotebook使用中的错误集锦