3

For a while now, I've been happily exporting a Python executable of my Jupyter notebook by running

 jupyter nbconvert --to script notebook.ipynb

which creates notebook.py. OK, actually, I've been executing

!jupyter nbconvert --to script $s_script_path

from inside the notebook, but that shouldn't be any different.

Today, suddenly, the same command runs and produces a file notebook.txt instead of .py. (With minor differences, e.g., the commented lines like In[1]: aren't there anymore.) Why would this be, and how do I get back to the other way?

P.S. This seemed to happen after I changed and re-saved the .py file in an external editor. Can't imagine why that should make a difference, though.

4

3 回答 3

3

if you are getting txt file instead of py then type following command:

jupyter nbconvert --to script filename.ipynb --to python
于 2020-06-14T09:20:01.647 回答
2

我经历了同样的事情并发现它正在发生,因为我使用 Pycharm 而不是 Jupyter 来生成笔记本。Jupyter 将一些元数据放在了 Pycharm 没有的笔记本中。因此,如果再次发生这种情况,请检查笔记本元数据。

于 2019-03-13T22:23:14.447 回答
1

这没什么。重新启动 jupyter 清除它。顺便说一句,这个问题在 Jupyter 的“文件”菜单中也很明显,其中“下载为”选项开始只显示 .txt 选项而不是 .py 选项。重启后,这也清除了。

于 2018-02-06T15:22:47.047 回答