当前位置:网站首页>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
成功了啊啊啊啊啊
边栏推荐
猜你喜欢
随机推荐
Date类中日期转成指定字符串出现的问题及解决方法
How much do you know about the bank deposit business that software test engineers must know?
The difference of time zone and the time library of go language
[designmode] adapter pattern
软件测试工程师必会的银行存款业务,你了解多少?
Senparc. Weixin. Sample. MP source code analysis
Atcoder beginer contest 254 [VP record]
Learn PWN from CTF wiki - ret2libc1
如何解决ecology9.0执行导入流程流程产生的问题
FFMPEG关键结构体——AVFormatContext
SQLServer连接数据库读取中文乱码问题解决
FFT learning notes (I think it is detailed)
[Chongqing Guangdong education] Chongqing Engineering Vocational and Technical College
Atcoder beginer contest 258 [competition record]
LeetCode 1189. Maximum number of "balloons"
Teach you to run uni app with simulator on hbuilderx, conscience teaching!!!
PV static creation and dynamic creation
Recognize the small experiment of extracting and displaying Mel spectrum (observe the difference between different y_axis and x_axis)
MySQL global lock and table lock
Codeforces Round #804 (Div. 2)【比赛记录】