Reputation: 1069
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
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
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
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