如何在只读Jupyter Noteb中保存更改

2024-06-06 14:59:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我打开了一个python Jupyter笔记本,但没有注意到它处于只读模式,而不是可信模式。现在如何保存我的更改?

我尝试过但没有帮助的事情:

  • 文件->;复制
  • 文件->;保存和检查点
  • 文件->;下载为
  • 文件->;信任笔记本

Tags: 文件gt模式笔记本jupyter事情检查点信任
3条回答

围绕这个问题的一个技巧是:

  1. 选择只读笔记本中的所有单元格(或需要的单元格)。通过单击第一个单元格,然后按住shift键并单击最后一个单元格,可以选择所有单元格。
  2. 使用CTRL+C复制所有单元格(如果使用MAC,则使用COMMAND+C)
  3. 创建新的jupyter笔记本页
  4. 单击CTRL+V(如果使用MAC,则单击COMMAND+V)两次
  5. 保存新笔记本

希望这个黑客能帮上忙

这里有一个更专业的答案,它提供了一个服务器端解决方案,可以从命令行使用,也可以编程使用。

https://jupyter-notebook.readthedocs.io/en/latest/notebook.html#introduction

Trusting Notebooks To prevent untrusted code from executing on users’ behalf when notebooks open, we store a signature of each trusted notebook. The notebook server verifies this signature when a notebook is opened. If no matching signature is found, Javascript and HTML output will not be displayed until they are regenerated by re-executing the cells.

Any notebook that you have fully executed yourself will be considered trusted, and its HTML and Javascript output will be displayed on load.

If you need to see HTML or Javascript output without re-executing, and you are sure the notebook is not malicious, you can tell Jupyter to trust it at the command-line with:

$ jupyter trust mynotebook.ipynb 

See Security in notebook documents for more details about the trust mechanism.

我同意上面的第一个答案,但您必须再包含一个步骤(下面的步骤4),以便所有复制的单元格都不会粘贴到单个单元格中。

1) Select all cells (or cells that you need) in your read-only notebook. You can select all cells by clicking on the first cell and then shift+clicking the last cell.
2) Copy all cells using CTRL+C (COMMAND+C if you are using MAC)
3) Create a new jupyter notebook page

4) CLICK IN THE MARGIN OF THE NEW CELL (***to close it for editing***), then...

5) Click CTRL+V (COMMAND+V if you are using MAC) 
6) Save your new notebook

默认情况下,Jupyter会将光标插入第一个单元格,第一个单元格将打开光标进行编辑。

若要避免将所有内容粘贴到打开进行编辑的单元格中,必须关闭该单元格进行编辑。

相关问题 更多 >