中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Jupyter?Notebook運行代碼無反應如何解決

發布時間:2023-01-05 09:48:26 來源:億速云 閱讀:185 作者:iii 欄目:開發技術

這篇文章主要介紹“Jupyter Notebook運行代碼無反應如何解決”,在日常操作中,相信很多人在Jupyter Notebook運行代碼無反應如何解決問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”Jupyter Notebook運行代碼無反應如何解決”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!

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.

然后參考http://www.5655pk.com/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運行代碼無反應如何解決

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 函數里的切片賦值語句,發現這段代碼很快結束,至此問題有三個:切片不可直接賦值,標準輸出不可靠,每個提示都要細看。

到此,關于“Jupyter Notebook運行代碼無反應如何解決”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續學習更多相關知識,請繼續關注億速云網站,小編會繼續努力為大家帶來更多實用的文章!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

云阳县| 清流县| 鸡西市| 商水县| 鹤山市| 彝良县| 赤壁市| 原阳县| 绥中县| 临城县| 四川省| 秦皇岛市| 千阳县| 万载县| 潼关县| 建宁县| 东乌| 宁乡县| 宜宾市| 印江| 滁州市| 贺州市| 云林县| 青冈县| 山东省| 平乐县| 京山县| 双峰县| 汨罗市| 鹤壁市| 桐庐县| 无锡市| 南皮县| 宁强县| 东莞市| 方正县| 壶关县| 贵德县| 阿勒泰市| 个旧市| 宜州市|