在 VSCode 中将 .ipynb 转换为 .py 的最佳方法
Best way to convert .ipynb to .py in VSCode
我正在寻找一种将 .ipynb 转换为 VSCode 中的 .py 文件的好方法。到目前为止我已经尝试过:
- vscode 中内置的“导出为”选项。不理想,因为它会在脚本开头生成以下内容,以及“运行 Cell”、“运行 Below”等。buttons/links:
"To add a new cell, type '# %%' To add a new markdown cell, type '# %%
[markdown]' %% from IPython import get_ipython"
nbconvert。我通常将其作为命令插入脚本本身 (),因此它会自动转换并保存一次 运行。但这也会留下“运行 Cell”等,以及执行标记(例如:“In [1]”)
jupytext。我通常也将其作为命令插入。在 .py 的开头,它产生:
-- coding: utf-8 --
--- jupyter: jupytext:
text_representation:
有没有一个很好的、极简主义的解决方案,它不会在我的笔记本的 .py 版本中插入一堆垃圾(需要手动编辑掉)并且可以 easily/automatically 从笔记本中执行本身?这也可能是我目前不知道的设置调整,可以使我提到的其中一件事更好地工作。
提前致谢。
我们可以在“settings.json
”中添加如下设置,生成的python文件将不会有“运行单元格”、“运行以上”、“调试单元":
"jupyter.codeLenses": " ",
我发现有一种方法可以在 VS Code 中导出权限:
https://code.visualstudio.com/docs/python/jupyter-support-py
Export a Jupyter notebook
In addition to opening a Jupyter notebook, you can also use one of the
following commands from the Command Palette (⇧⌘P) to export content
from a Python file in VS Code to a Jupyter notebook (with the .ipynb
extension).
- Jupyter: Export Current Python File as Jupyter Notebook: creates a Jupyter notebook from the contents of the current file, using the
# %%
and # %% [markdown]
delimiters to specify their respective cell types.
- Jupyter: Export Current Python File and Output as Jupyter Notebook: creates a Jupyter notebook from the contents of the current file and includes output from code cells.
- Jupyter: Export Interactive Window as Jupyter Notebook: creates a Jupyter notebook from the contents of the Python Interactive window.
After exporting the contents, VS Code displays a prompt through which you can open the notebook in a browser.
首先,您需要安装Jupyter包:
https://marketplace.visualstudio.com/items?itemName=ms-toolsai.jupyter
第二次打开“命令面板”(⇧⌘P) 并搜索这一行:
Jupyter:导出到 Python 脚本
我正在寻找一种将 .ipynb 转换为 VSCode 中的 .py 文件的好方法。到目前为止我已经尝试过:
- vscode 中内置的“导出为”选项。不理想,因为它会在脚本开头生成以下内容,以及“运行 Cell”、“运行 Below”等。buttons/links:
"To add a new cell, type '# %%' To add a new markdown cell, type '# %% [markdown]' %% from IPython import get_ipython"
nbconvert。我通常将其作为命令插入脚本本身 (),因此它会自动转换并保存一次 运行。但这也会留下“运行 Cell”等,以及执行标记(例如:“In [1]”)
jupytext。我通常也将其作为命令插入。在 .py 的开头,它产生:
-- coding: utf-8 -- --- jupyter: jupytext: text_representation:
有没有一个很好的、极简主义的解决方案,它不会在我的笔记本的 .py 版本中插入一堆垃圾(需要手动编辑掉)并且可以 easily/automatically 从笔记本中执行本身?这也可能是我目前不知道的设置调整,可以使我提到的其中一件事更好地工作。
提前致谢。
我们可以在“settings.json
”中添加如下设置,生成的python文件将不会有“运行单元格”、“运行以上”、“调试单元":
"jupyter.codeLenses": " ",
我发现有一种方法可以在 VS Code 中导出权限:
https://code.visualstudio.com/docs/python/jupyter-support-py
Export a Jupyter notebook
In addition to opening a Jupyter notebook, you can also use one of the following commands from the Command Palette (⇧⌘P) to export content from a Python file in VS Code to a Jupyter notebook (with the
.ipynb
extension).
- Jupyter: Export Current Python File as Jupyter Notebook: creates a Jupyter notebook from the contents of the current file, using the
# %%
and# %% [markdown]
delimiters to specify their respective cell types.- Jupyter: Export Current Python File and Output as Jupyter Notebook: creates a Jupyter notebook from the contents of the current file and includes output from code cells.
- Jupyter: Export Interactive Window as Jupyter Notebook: creates a Jupyter notebook from the contents of the Python Interactive window.
After exporting the contents, VS Code displays a prompt through which you can open the notebook in a browser.
首先,您需要安装Jupyter包:
https://marketplace.visualstudio.com/items?itemName=ms-toolsai.jupyter
第二次打开“命令面板”(⇧⌘P) 并搜索这一行:
Jupyter:导出到 Python 脚本