解决jupyter notebook无法连接/jupyter notebook无法连接到kernel
解决No module named ‘torch
环境:Ubuntu18.04 Anaconda3 cpu
背景:
昨天在进入jupyter notebook时提示:
A connection to the notebook server could not be established. The notebook will continue trying to reconnect
我之前遇到过这种情况也搜索过其原因,主要原因就是各个包资源之间版本不配的问题,比如你想要运行新程序可能要配置新环境,把某些包换成高版本或者低版本,这样就有可能导致某些包版本产生冲突,使jupyter notebook 无法连接到kernel。
常见的其他报错:
1.RuntimeWarning: Enable tracemalloc to get the object allocation traceback
2.Enable tracemalloc to get the object allocation traceback
3.TypeError: __init__() got an unexpected keyword argument 'io_loop'
初级解决办法:
1.如果你的python版本是3.8,首先查看一下pyzmq的版本
pip list
把pyzmq的版本更改到19.0.2
卸载pyzmq
pip uninstall pyzmq
安装19.0.2版本pyzmq
pip install pyzmq==19.0.2
2.查看自己的ipykernel的版本,如果ipykernel的大于5.0,可以把ipykernel的版本更改到4.9.0
先卸载ipykernel
pip uninstall ipykernel
安装4.9.0版本ipykernel
pip install ipykernel==4.9.0
3.在jupyter启动时,报错TypeError: __init__() got an unexpected keyword argument 'io_loop'
查看tornado版本,找到tornado版本的版本
pip list
如果大于6.0.0以上,先卸载tornado:
pip uninstall tornado
安装低版本的tornado:
pip install tornado==4.2
终极解决办法:
卸载PyTorch重装
uninstall和install pytorch 有两个地方容易搞混,就比如我之前在base环境中安装了pytorch但是在虚拟pytorch环境中是没办法用的,同样也就是在这里出现“no moduel named torch”困扰我很久。
为了解决这个问题,首先在base环境中查看是否安装了PyTorch以及版本
conda list
可以看到我base环境中pytorch版本是1.4.0
再在pytorch环境中查看是否安装了PyTorch以及版本
可以看到我pytorch环境中pytorch版本是1.7.1
这样无论在base环境还是pytorch环境import torch都没问题了
如果没有安装pytorch
注意在base和虚拟pytorch环境中都安装pytorch
1.在清华镜像网站选择适合的版本进行pytorch安装(推荐)
步骤:1.找到合适的版本下载,注意Torchvision版本对应问题
2.在下载文件夹的位置打开终端
3.
conda install pytorch-1.7.0-py3.8_cpu_0.tar.bz2
其中pytorch-1.7.0-py3.8_cpu_0.tar.bz2是文件夹的名称
参考:解决jupyter notebook无法连接/ jupyter连接不到kernel解决方案_Jiuba_9898的博客-CSDN博客_jupyter无法连接