当前位置:网站首页>anconda下载+添加清华+tensorflow 安装+No module named ‘tensorflow‘+KernelRestarter: restart failed,内核重启失败
anconda下载+添加清华+tensorflow 安装+No module named ‘tensorflow‘+KernelRestarter: restart failed,内核重启失败
2022-07-06 00:17:00 【是Yu欸】
又换电脑了,重新下载配置
一、aconda下载
https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/
conda channel的镜像设置(参考https://blog.csdn.net/weixin_39278265/article/details/84782550)
显示所有channel
conda config --show channels
二、添加可用的清华源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes
conda config --set show_channel_urls yes的意思是从channel中安装包时显示channel的url,这样就可以知道包的安装来源了。
(3)输入conda config --show channels查看一下是否添加成功。
根据自己添加的镜像源显示,你添加了哪个,就显示哪个。
三、tensorflow 的安装
(1)win+r输入cmd,检查anaconda安装:在cmd输入 conda --version
(2)检测已经安装的环境:conda info --envs
这里如果没有新建其他环境的话,就只有一个默认的anaconda中的root环境。
(3)新建一个python3.5的环境,tensorflow:conda create --name tensorflow python=3.6
系统会自动选择分配一个python3.6.x的版本
(4)检查是否创建成功:conda info --envs
(5)激活新建的环境:activate tensorflow
注意一定要进入到tensorflow中,否则你会安装到其他环境中,导致无法使用。
(6)查询tensorflow的版本号
conda search tensorflow
(7)选择自己想安装的版本号。conda install tensorflaw=版本号
(如:conda install tensorflaw=2.0.0)然后回车,等待即可。
如果安装完之后出现了以下错误
Fatal Python error: Py_Initialize: can’t initialize sys standard streams LookupError: unknown encoding: 65001
可以在命令窗口输入即可 set PYTHONIOENCODING=UTF-8
4.检测tensorflow是否安装成功
(1)打开cmd,激活新建的环境(切换到tensorflow环境):activate tensorflow
(2)进入python
(3)然后输入一个tensorflow版本1.5的测试代码:如果输出结果3,说明已经成功安装tensorflow。
import tensorflow as tf
sess = tf.Session()
a = tf.constant(1)
b = tf.constant(2)
print(sess.run(a+b))
tensorflow版本2.0的测试代码:
import tensorflow as tf
#查看tensorflow版本
print(tf.__version__)
print('GPU', tf.test.is_gpu_available())
a = tf.constant(2.0)
b = tf.constant(4.0)
print(a + b)

四、问题与解决
1、报错:No module named ‘tensorflow’
参考:https://blog.csdn.net/qq_40305998/article/details/105677341
windows终端可以import tensorflow,jupyter不可以的解决办法

若不相同,则说明有问题。
在终端中输入:
jupyter kernelspec list
显示已经已添加的kernel
然后输入:
conda install pip
conda install ipykernel
python -m ipykernel install --user --name tensorflow --display-name tensor
其中:
python -m ipykernel install --user --name “环境名称” --display-name “想要命名的Python名称”
再输入:
jupyter kernelspec list
可以看到多出一个kernel。
打开jupyter notebook,可以看到多出一个名为tensor的kernel。
新建tensor的notebook文件,就可以解决问题
也可以使用:
jupyter kernelspec remove tensorflow
删除创建的kernel。
其中
jupyter kernelspec remove <kernel_name>
再输入:
jupyter kernelspec list
打开jupyter,创建的Python已被删除。
2、Kernel does not exist
参考https://blog.csdn.net/Julse/article/details/102555574
在pycharm的terminal终端中,首次启动jupyter notebook,成功。中断之后重启,运行cell的时候找不到kernels,系统报错如下
(topvenv)..../feature190919>jupyter notebook
[I 11:11:59.261 NotebookApp] Serving notebooks from local directory: ..../feature190919
[I 11:11:59.261 NotebookApp] The Jupyter Notebook is running at:
[I 11:11:59.261 NotebookApp] http://localhost:8888/?token=...
[I 11:11:59.262 NotebookApp] or http://127.0.0.1:8888/?token=...
[I 11:11:59.262 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[W 11:15:08.362 NotebookApp] No session ID specified
[W 11:15:08.362 NotebookApp] 404 GET /api/kernels/96b59d42-d81e-471c-8ef9-63a61a963a16/channels (127.0.0.1): Kernel does not exist: 96b59d42-d81e-471c-8ef9-63a61a963a16
[W 11:15:08.369 NotebookApp] 404 GET /api/kernels/96b59d42-d81e-471c-8ef9-63a61a963a16/channels (127.0.0.1) 9.02ms referer=None
[I 11:21:39.267 NotebookApp] Interrupted...
[I 11:21:39.268 NotebookApp] Shutting down 0 kernels
解决方案(失败):
找到这个runtime目录,全部清空,重启jupyter就可以了(注意APPData为隐藏的文件夹)

下面是我对这个错误的分析和解决思路
我直接把token的参数填了密码导致了本次错误
观察该目录,一启动jupyter notebook就生成了这三个文件
用记事本打开nbserver-2280.json文件,会发现123456并没有进入到password字段中,而是被放入到了token字段。这个时候在pycharm中点击
这时候会重新提示输入密码
输入密码之后保存就对了。
在cmd窗口中通过pip install jupyter安装成功之后,运行jupyter notebook,运行代码,发现代码左侧In [ ]变成了In [*],发现在cmd窗口中报错如下:
3、KernelRestarter: restart failed,内核重启失败
在这个上面还有一大段报错,大概意思就是在不断尝试重启内核,看报错,主要是KernelRestarter: restart failed,内核重启失败
解决方案(成功):
pip install --upgrade ipykernel
将其升级即可正常运行,虽然它会提示你prompt-toolkit的版本应该在1.0到2.0之间,但是这并不影响jupyter notebook的运行,在升级过程中,主要更新的模块就是prompt_toolkit,看来是因为这个模块的版本过低导致
参考:https://blog.csdn.net/weixin_40820983/article/details/102798873
因为需要升级某些包的版本,用 pip install --upgrade ***命令更新,但出现无法卸载的情况:
ERROR: Cannot uninstall ‘scikit-learn’. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
有的回答说用
pip install --ignore-installed ipykernel
但是旧版本还在,会有其他问题出现。
其实只要找到你的python中的安装包,删除所有与它相关的文件即可。(所有名字里含有该模块的文件都要删完)
例如在文件夹 :anaconda\Lib\site-package
D:\Program\Anaconda\envs\tensorflow\Lib\site-packages
参考:https://blog.csdn.net/qq_45371443/article/details/119008541
conda install tensorflow-estimator==2.0.0

然后重新安装,成功!!!
pip install --ignore-installed ipykernel


成功了啊啊啊啊啊
边栏推荐
- 关于结构体所占内存大小知识
- LeetCode 1598. Folder operation log collector
- Key structure of ffmpeg - avframe
- DEJA_ Vu3d - cesium feature set 055 - summary description of map service addresses of domestic and foreign manufacturers
- Mysql - CRUD
- DEJA_VU3D - Cesium功能集 之 055-国内外各厂商地图服务地址汇总说明
- Classical concurrency problem: the dining problem of philosophers
- 提升工作效率工具:SQL批量生成工具思想
- JS 这次真的可以禁止常量修改了!
- Codeforces Round #804 (Div. 2)【比赛记录】
猜你喜欢

Tools to improve work efficiency: the idea of SQL batch generation tools

【NOI模拟赛】Anaid 的树(莫比乌斯反演,指数型生成函数,埃氏筛,虚树)
![[binary search tree] add, delete, modify and query function code implementation](/img/38/810a83575c56f17a7a0ed428a2e02e.png)
[binary search tree] add, delete, modify and query function code implementation

FFMPEG关键结构体——AVFormatContext

Huawei equipment configuration ospf-bgp linkage

电机的简介

Detailed explanation of APP functions of door-to-door appointment service

MySQL之函数

时间戳的拓展及应用实例

选择致敬持续奋斗背后的精神——对话威尔价值观【第四期】
随机推荐
Miaochai Weekly - 8
Extracting profile data from profile measurement
notepad++正则表达式替换字符串
Determinant learning notes (I)
云呐|公司固定资产管理系统有哪些?
QT QPushButton details
N1 # if you work on a metauniverse product [metauniverse · interdisciplinary] Season 2 S2
从底层结构开始学习FPGA----FIFO IP核及其关键参数介绍
The global and Chinese markets of dial indicator calipers 2022-2028: Research Report on technology, participants, trends, market size and share
多线程与高并发(8)—— 从CountDownLatch总结AQS共享锁(三周年打卡)
Hardware and interface learning summary
亲测可用fiddler手机抓包配置代理后没有网络
PHP determines whether an array contains the value of another array
[noi simulation] Anaid's tree (Mobius inversion, exponential generating function, Ehrlich sieve, virtual tree)
建立时间和保持时间的模型分析
OpenCV经典100题
Effet Doppler (déplacement de fréquence Doppler)
Global and Chinese markets of universal milling machines 2022-2028: Research Report on technology, participants, trends, market size and share
Configuring OSPF GR features for Huawei devices
Global and Chinese markets for hinged watertight doors 2022-2028: Research Report on technology, participants, trends, market size and share