Jupyter Notebook运行代码无反应问题及解决方法

 更新时间:2023年1月6日 14:47  点击:519 作者:温馨娜

Jupyter Notebook运行代码无反应

在学习人脸识别知识的过程中需要用到Anaconda 、Jupyter Notebook.

我在启动Jupyter Notebook后,新建代码运行无反应。

从页面上也观察不出来是什么问题,后来在Anaconda Pormpt中启动Jupyter Notebook,我一开始还以为是自动启动的,傻傻的等它自动运行。。。

结果是在浏览器中操作,命令行中才会跑模块的运行情况。

要在浏览器中shift+enter执行代码片段,后台包这个错误。

 
(tensorflow) C:\Users\admin>jupyter notebook
[I 15:55:33.979 NotebookApp] The port 8888 is already in use, trying another port.
[I 15:55:34.011 NotebookApp] The port 8889 is already in use, trying another port.
[I 15:55:34.130 NotebookApp] Serving notebooks from local directory: C:\Users\admin
[I 15:55:34.131 NotebookApp] The Jupyter Notebook is running at:
[I 15:55:34.137 NotebookApp] http://localhost:8890/?token=7d8aff641154f969e61dec8ebd511d98849f08829e440fe0
[I 15:55:34.139 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 15:55:34.220 NotebookApp]
 
    To access the notebook, open this file in a browser:
        file:///C:/Users/admin/AppData/Roaming/jupyter/runtime/nbserver-24428-open.html
    Or copy and paste one of these URLs:
        http://localhost:8890/?token=7d8aff641154f969e61dec8ebd511d98849f08829e440fe0
Traceback (most recent call last):
  File "C:\Users\admin\Anaconda3\envs\tensorflow\lib\site-packages\tornado\ioloop.py", line 888, in start
    handler_func(fd_obj, events)
  File "C:\Users\admin\Anaconda3\envs\tensorflow\lib\site-packages\tornado\stack_context.py", line 277, in null_wrapper
    return fn(*args, **kwargs)
  File "C:\Users\admin\Anaconda3\envs\tensorflow\lib\site-packages\zmq\eventloop\zmqstream.py", line 450, in _handle_events
    self._handle_recv()
  File "C:\Users\admin\Anaconda3\envs\tensorflow\lib\site-packages\zmq\eventloop\zmqstream.py", line 480, in _handle_recv
    self._run_callback(callback, msg)
  File "C:\Users\admin\Anaconda3\envs\tensorflow\lib\site-packages\zmq\eventloop\zmqstream.py", line 432, in _run_callback
    callback(*args, **kwargs)
  File "C:\Users\admin\Anaconda3\envs\tensorflow\lib\site-packages\tornado\stack_context.py", line 277, in null_wrapper
    return fn(*args, **kwargs)
  File "C:\Users\admin\Anaconda3\envs\tensorflow\lib\site-packages\ipykernel\kernelbase.py", line 283, in dispatcher
    return self.dispatch_shell(stream, msg)
  File "C:\Users\admin\Anaconda3\envs\tensorflow\lib\site-packages\ipykernel\kernelbase.py", line 233, in dispatch_shell
    self.pre_handler_hook()
  File "C:\Users\admin\Anaconda3\envs\tensorflow\lib\site-packages\ipykernel\kernelbase.py", line 248, in pre_handler_hook
    self.saved_sigint_handler = signal(SIGINT, default_int_handler)
  File "C:\Users\admin\Anaconda3\envs\tensorflow\lib\signal.py", line 47, in signal
    handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
ValueError: signal only works in main thread
[IPKernelApp] WARNING | Parent appears to have exited, shutting down.

然后参考https://www.jb51.net/article/271651.htm  解决。

(tensorflow) C:\Users\admin>pip install "pyzmq==17.0.0" "ipykernel==4.8.2"
Collecting pyzmq==17.0.0
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)",)': /simple/pyzmq/
  Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)",)': /simple/pyzmq/
  Downloading https://files.pythonhosted.org/packages/27/0b/a275f30738a014dc25443d2f45156ca739991df581fdaa40aa19df6c4f86/pyzmq-17.0.0-cp36-cp36m-win_amd64.whl (944kB)
    100% |████████████████████████████████| 952kB 49kB/s
Collecting ipykernel==4.8.2
  Downloading https://files.pythonhosted.org/packages/ab/3f/cd624c835aa3336a9110d0a99e15070f343b881b7d651ab1375ef226a3ac/ipykernel-4.8.2-py3-none-any.whl (108kB)
    100% |████████████████████████████████| 112kB 58kB/s
Requirement already satisfied: ipython>=4.0.0 in c:\users\admin\anaconda3\envs\tensorflow\lib\site-packages (from ipykernel==4.8.2) (6.1.0)
Requirement already satisfied: tornado>=4.0 in c:\users\admin\anaconda3\envs\tensorflow\lib\site-packages (from ipykernel==4.8.2) (4.5.2)
Requirement already satisfied: traitlets>=4.1.0 in c:\users\admin\anaconda3\envs\tensorflow\lib\site-packages (from ipykernel==4.8.2) (4.3.2)
Requirement already satisfied: jupyter-client in c:\users\admin\anaconda3\envs\tensorflow\lib\site-packages (from ipykernel==4.8.2) (5.2.4)
Requirement already satisfied: jupyter-core in c:\users\admin\anaconda3\envs\tensorflow\lib\site-packages (from jupyter-client->ipykernel==4.8.2) (4.4.0)
Requirement already satisfied: python-dateutil>=2.1 in c:\users\admin\anaconda3\envs\tensorflow\lib\site-packages (from jupyter-client->ipykernel==4.8.2) (2.6.1)
Requirement already satisfied: six>=1.5 in c:\users\admin\anaconda3\envs\tensorflow\lib\site-packages (from python-dateutil>=2.1->jupyter-client->ipykernel==4.8.2) (1.10.0)
Installing collected packages: pyzmq, ipykernel
  Found existing installation: pyzmq 17.1.2
    Uninstalling pyzmq-17.1.2:
      Successfully uninstalled pyzmq-17.1.2
  Found existing installation: ipykernel 4.6.1
Cannot uninstall 'ipykernel'. 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.

安装时报错,ipykernel不能卸载,我也尝试过重新装,一直报这个错误。索性没管它,直接再浏览器中重新运行就可以正常运行了。

这是修复后的运行效果。

jupyter notebook 某个cell 一直在运行

近期调试程序,发现一简单的代码一直在运行,很长时间不终止,代码如下:

whole_df=pd.read_csv(r'./train.csv')
 
community=whole_df['COMMUNITY_ID'].unique()
 
for community_id in community:
 
    temp=check_result[check_result['COMMUNITY_ID']==community_id]
 
    start=temp.index.tolist()[0]
 
    delanomaly_test(temp,start) 

其中delanomaly_test 是对测试数据进行处理异常值的函数,函数里有对形参temp进行赋值的操作,而temp 是whole_df的切片,执行后,出现了很多提示:

/usr/local/python3/lib/python3.6/site-packages/pandas/core/indexing.py:1763: SettingWithCopyWarning:


A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy

一大串的全是提示,而且还一直扩展向下,过了10分钟,不再出现提示,但是这段cell 执行符号里显示‘*’,为一直在执行,本身数据量不大,community 为200个,check_result为8万条,应该2、3分钟就结束了但是又过5分钟还是‘*’号,点‘Interrupt the kernel ’也是很长时间没反应。用写标准输出+写文件的方式测试下:

whole_df=pd.read_csv(r'./train.csv')
 
community=whole_df['COMMUNITY_ID'].unique()
filename='proeceeing.txt'
 
with open(file_name,'w+') as f:
 
    f.write(file_name)
 
w=0 #进度的变量
 
for community_id in community:
 
    if w%50==0:
 
        print('w=%s' %str(w)) #打印至标准输出
 
        f=open(file_name,'a')
 
        f.write('\n     '+str(w)+':')#写入文件
 
        f.write(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())))  
 
        f.close()
 
    temp=check_result[check_result['COMMUNITY_ID']==community_id]
 
    start=temp.index.tolist()[0]
 
    delanomaly_test(temp,start)
 
    w=w+1
print('w=%s' %str(w)) #打印至标准输出
 
f=open(file_name,'a')
 
print('w=%s' %str(w))
 
f.write('\n     '+str(w)+':') #写入文件
 
f.write(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())))
 
f.write('\n check_result executed ')
 
f.close()

执行后,文件内容如下:

processing.txt
     0:2021-08-25 21:14:38
     50:2021-08-25 21:14:43
     100:2021-08-25 21:14:49
     150:2021-08-25 21:14:54
     200:2021-08-25 21:15:00
 check_result executed 

看来这段代码在一分钟之内已经执行完毕,再看标准输出,还是有很多之前的提示,同时标示进度的w值里,只发现了三条:

w=0

w=50

w=100

再向后就只有提示,再向后提示也终止了

因此这段代码一直执行的可能原因是短时间内写大量内容至标准输出,标准输出缓冲区满,无法打印提示和之后的内容,但程序实际已执行完毕。最后删除delanomaly_test 函数里的切片赋值语句,发现这段代码很快结束,至此问题有三个:切片不可直接赋值,标准输出不可靠,每个提示都要细看

总结

以上为个人经验,希望能给大家一个参考,也希望大家多多支持猪先飞。

原文出处:https://blog.csdn.net/qq_34733907/article/details/88822786

[!--infotagslink--]

相关文章

  • Jupyter Notebook读取csv文件出现的问题及解决

    这篇文章主要介绍了JupyterNotebook读取csv文件出现的问题及解决,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教...2023-01-06
  • Jupyter Notebook运行JavaScript的方法

    Jupyter Notebook是一块所见即所得的画布,通过在浏览器上编辑代码,让开发人员实现展示与快速迭代的利器,本文主要介绍了Jupyter Notebook运行JavaScript的方法,感兴趣的可以了解一下...2021-05-16
  • jupyter notebook中图片显示不出来的解决

    这篇文章主要介绍了jupyter notebook中图片显示不出来的解决操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-03-24
  • 详解运行Python的神器Jupyter Notebook

    如果我们想要运行Python,就是在Python或者IPython的解释器环境中进行交互式运行,或者程序员最喜欢的编写.py文件,在文件中编写python代码,然后运行。如果想写一篇Python的文章,里面有代码,还希望代码在当前页面运行,那就是使用我们今天要介绍的Jupyter Notebook。...2021-06-03
  • jupyter读取错误格式文件的解决方案

    这篇文章主要介绍了jupyter读取错误格式文件的解决方案,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-03-25
  • 关于jupyter lab安装及导入tensorflow找不到模块的问题

    这篇文章主要介绍了关于jupyter lab安装及导入tensorflow找不到模块的问题,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2021-03-16
  • jupyter .ipynb转.py的实现操作

    这篇文章主要介绍了jupyter .ipynb转.py的实现操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-03-24
  • Jupyter Notebook 安装配置与使用详解

    这篇文章主要介绍了Jupyter Notebook 安装配置与使用详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-01-06
  • 详解解决jupyter不能使用pytorch的问题

    这篇文章主要介绍了详解解决jupyter不能使用pytorch的问题,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-02-18
  • Jupyter notebook命令和编辑模式常用快捷键汇总

    这篇文章主要介绍了Jupyter notebook命令和编辑模式常用快捷键汇总,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-11-18
  • 详解如何修改jupyter notebook的默认目录和默认浏览器

    这篇文章主要介绍了详解如何修改jupyter notebook的默认目录和默认浏览器,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-01-25
  • jupyter notebook快速入门及使用详解

    这篇文章主要介绍了jupyter notebook快速入门及使用详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-11-13
  • 使用Atom支持基于Jupyter的Python开教程详解

    这篇文章主要介绍了使用Atom支持基于Jupyter的Python开发,Vscode虽然说也有连接Jupyter的工具,但是交互式的开发Hydrogen体验更好,需要的朋友可以参考下...2021-08-22
  • 详解修改Anaconda中的Jupyter Notebook默认工作路径的三种方式

    这篇文章主要介绍了详解修改Anaconda中的Jupyter Notebook默认工作路径的三种方式,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-01-25
  • 解决Jupyter 文件路径的问题

    这篇文章主要介绍了解决Jupyter 文件路径的问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-03-24
  • python入门jupyter基础操作及文本用法

    这篇文章主要介绍了python入门-jupyter基础操作及文本用法,适合入门的python小白阅读,有需要的朋友可以借鉴参考下,希望可以有所帮助,感谢阅读...2021-09-06
  • docker容器下配置jupyter notebook的操作

    这篇文章主要介绍了docker容器下配置jupyter notebook的操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-03-24
  • Jupyter Notebook运行代码无反应问题及解决方法

    这篇文章主要介绍了JupyterNotebook运行代码无反应问题及解决方法,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教...2023-01-06
  • 在jupyter notebook中使用pytorch的方法

    这篇文章主要介绍了在jupyternotebook中使用pytorch的方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2022-09-16