直接启动jupyter notebook,在jupyter notebook中输入命令,如import tensorflow as tf并不能调用tensorflow的开发包。
![img](https://pic2.zhimg.com/80/v2-0bc09fab2f942417725c63748f4cb695_720w.jpg)
这是因为:如果此时直接启动jupyter,此时的jupyter是基于整个Anaconda的python,而不是对应的tensorflow虚拟环境,因此进入此虚拟环境后需要重新安装jupyter notebook
在TensorFlow的虚拟环境(tensorflow_env)安装jupyter
激活环境TensorFlow
在cmd中输入:conda activate tensorflow_env
![img](https://pic2.zhimg.com/80/v2-6fdc15b5329d9f30517987b0ceca85fd_720w.jpg)
安装ipython
在cmd中输入:conda install ipython
![img](https://pic1.zhimg.com/80/v2-457880f62390cd3dea174f996f6f7254_720w.jpg)
安装jupyter
在cmd中输入:conda install jupyter
这里看到有些人会出现以下问题,当然也许你不会出现也许你会出现。
![img](https://pic2.zhimg.com/80/v2-7bdb8544188255285cc090baa4b4ebf5_720w.png)
![img](https://pic2.zhimg.com/80/v2-f6ca0c77c8549dae58cf2aca1907f751_720w.jpg)
这个问题是“无法定位程序的输入点 xxx 于动态链接库 xxx 上”,我们来解决一下。
在cmd中输入:pip install jupyter (pip是 Python 包管理工具,该工具提供了对Python 包的查找、下载、安装、卸载的功能。) 出现好多下载列表……慢慢等待进度条
![img](https://pic1.zhimg.com/80/v2-fb08c146e4f99b126c27506184c9e774_720w.jpg)
直到出现2个“Successfully……”,说明这个过程结束
![img](https://pic3.zhimg.com/80/v2-bd31e8571548775e2c372c453a5194aa_720w.jpg)
安装python kernel for Tensorflow:
在cmd中输入:ipython kernelspec install-self --user
看到类似如下结果 Installed kernelspec python3 in C: 说明安装成功
![img](https://pic3.zhimg.com/80/v2-4d026c73a10a7bb8e7c961437496124a_720w.jpg)
验证是否好使
此时在tensorflow虚拟环境下,输入:jupyter notebook 会显示很多信息,不用管它
![img](https://pic3.zhimg.com/80/v2-a90de1867bf11b5201b329738a3216c6_720w.jpg)
然后自动跳转到tensorflow虚拟环境下的jupyter网页
![img](https://pic2.zhimg.com/80/v2-e194de4e0ba90ebfed8829a9826d7671_720w.jpg)
跑一下测试代码
import tensorflow as tf hello = tf.constant('hello,TensorFlow') sess = tf.Session() print(sess.run(hello))
![img](https://pic1.zhimg.com/80/v2-129e6e2b578c3014cf9d21698a674208_720w.jpg)
如果你和我有一样的结果,说明你成功了!!!
其他问题
我在第一次安装时,到了最后一部运行代码的时候,jupyter notebook切换新环境后,new新环境的notebook,服务器端会显示Bad file descriptor (D:_1605919615529.cpp:100) 然后就断掉jupyter notebook 服务。
正常情况下Jupyter Notebook是这样显示的:
![img](https://upload-images.jianshu.io/upload_images/25742462-51887c3bf000fde3.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/355/format/webp)
我的情况:
![img](https://upload-images.jianshu.io/upload_images/25742462-3dcf799d7cdef388.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/368/format/webp)
报错信息可能为:
![img](https://upload-images.jianshu.io/upload_images/25742462-573ad116ab6602b0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1051/format/webp)
也有可能是:
Bad address: C:.cpp:100
原因
当你安装jupyterlab 或者jupyter notebook的时候,会自动安装ipykernel, 然后自动安装了高版本的pyzmq.
解决方法
此问题是pyzmq版本问题,卸载pyzmq 22.0.2,执行 pip install pyzmq==19.0.2 安装pyzmq 19.0.2即可
1 | 卸载:pip uninstall pyzmq |
这个时候还要稍等一会,不要像我一样马上写代码然后发现还是运行不了!!!