David Kaufman
David Kaufman

Reputation: 1069

nbconvert suddenly producing .txt instead of .py

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.

Upvotes: 5

Views: 2006

Answers (3)

mubin basha
mubin basha

Reputation: 31

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

jupyter nbconvert --to script filename.ipynb --to python

Upvotes: 3

Narek
Narek

Reputation: 616

I experienced the same thing and found out it was happening because I used Pycharm to generate the notebook instead of Jupyter. Jupyter puts some metadata in the notebook that Pycharm does not. So check the notebook metadata if this happens again.

Upvotes: 2

David Kaufman
David Kaufman

Reputation: 1069

This was some kind of nothing. Restarting jupyter cleared it up. Incidentally, the problem was also visible in the Jupyter "File" menu, where the "Download As" option had started showing only a .txt option instead of a .py option. That, too, cleared up after the restart.

Upvotes: 1

Related Questions