![](/img/trans.png)
[英]What does In [*] in IPython Notebook mean and how to turn it off?
[英]Turn Off Autosave in IPython Notebook
我正在尋找一種在iPython筆記本中關閉自動保存的方法。 我已經通過Google / Stack Overflow搜索看到了有關如何打開自動保存的參考,但是我想相反(關閉自動保存)。 如果可以永久設置而不是在每個筆記本的頂部進行設置,那將是比較可取的。
一旦您在瀏覽器中的IPython Notebook中,將禁用自動保存: %autosave 0
。
更新 :JupyterLab中現在有一個UI功能: https : //github.com/jupyterlab/jupyterlab/pull/3734
如果將其添加到custom.js
,它將禁用所有筆記本的自動保存:
$([IPython.events]).on("notebook_loaded.Notebook", function () {
IPython.notebook.set_autosave_interval(0);
});
custom.js
在發現$(ipython locate profile)/static/custom/custom.js
。 您可以使用同一件事來增加或減少自動保存間隔。 該值以毫秒為單位,因此間隔30000表示每三十秒自動保存一次。
MinRK最初的解決方案已經過時,部分原因是IPython / Jupyter一直在變化很大。 除了這里的間接參考,我找不到合適的文檔,但是根據此論壇帖子 ,現在的解決方案似乎是編輯或創建~/.jupyter/custom/custom.js
,並添加線:
Jupyter.notebook.set_autosave_interval(0); // disable autosave
這對我有用。 您可以通過在啟動時在Jupyter筆記本右上角尋找簡短的“禁用自動保存”框來確認它是否有效。 論壇帖子中的完整解決方案對我不起作用,可能是因為它不再完全有效,並且custom.js文件中的錯誤似乎無聲地發生。
找到Jupyter配置文件夾:
from jupyter_core.paths import jupyter_config_dir jupyter_dir = jupyter_config_dir() # C:\\users\\<user_name>\\.jupyter on my machine
創建子文件夾custom
,並在其中創建文件custom.js
:
ie 'C:\\users\\<user_name>\\.jupyter\\custom\\custom.js'
將以下行放入custom.js中:
IPython.notebook.set_autosave_interval(0);
保存文件並重新啟動Jupyter Notebook服務器(主應用程序)。
打開筆記本時,菜單欄的右側會短暫顯示“禁用自動保存”:
從Jupyter 4.4(2019)開始,一種可行的解決方案是將其添加到您的custom.js文件中:
require(['base/js/namespace', 'base/js/events'], function (Jupyter, events) {
Jupyter.notebook.set_autosave_interval(0);
console.log("Auto-save has been disabled.");
});
沒有require
塊,JavaScript將在Jupyter
對象可用之前執行,從而導致錯誤。
為了清楚起見,custom.js應該駐留在〜/ .jupyter / custom / custom.js中-如果custom
目錄不存在,則必須創建它。
編輯 :在筆記本加載的自動保存間隔在Jupyter Notebook的最新版本( jupyter notebook --version
為6.0.1
)中jupyter notebook --version
。 所以我回到custom.js
解決方案:
mkdir -p ~/.jupyter/custom
echo "Jupyter.notebook.set_autosave_interval(0);" >> ~/.jupyter/custom/custom.js
正如上面的Thomas Maloney所指出的,JupyterLab現在有一個命令(在“ 設置”菜單中取消選中“ 自動保存文檔 ” )。
在Jupyter筆記本電腦,我覺得autosavetime
擴展相比,更便於使用custom.js
文件。 該autosavetime
擴展的一部分Jupyter筆記本擴展 ,可與安裝
pip install jupyter_contrib_nbextensions
jupyter contrib nbextension install
jupyter nbextension enable autosavetime/main
安裝完成后,重新啟動jupyter notebook
然后轉到“ 編輯”菜單中的nbextensions_config 。 選擇autosavetime
擴展,然后關閉自動保存,如下所示:
要測試修改,請執行以下操作:打開或創建Python筆記本,然后在新單元格中執行,
%%javascript
element.text(Jupyter.notebook.autosave_interval);
如果結果為0,則表示您已成功關閉自動保存功能。 恭喜你!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.