How do you convert an IPython notebook file (json with .ipynb
extension) into a regular .py
module?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
According to https://ipython.org/ipython-doc/3/notebook/nbconvert.html you are looking for the nbconvert command with the --to script option.
From the notebook menu you can save the file directly as a python script. Go to the 'File' option of the menu, then select 'Download as' and there you would see a 'Python (.py)' option.
Another option would be to use nbconvert from the command line:
Have a look here.
In short: This command-line option converts
mynotebook.ipynb
topython
code:jupyter nbconvert mynotebook.ipynb --to python
note: this is different from above answer.
ipython
has been renamed tojupyter
. the old executable name (ipython) is deprecated.More details:
jupyter
command-line has annbconvert
argument which helps convert notebook files(*.ipynb)
to various other formats.You could even convert it to any one of these formats using the same command but different
--to
option:well first of all you need to install this packege below:
two option is avaliable either --to python or --to=python mine was like this works fine: jupyter nbconvert --to python while.ipynb
[NbConvertApp] Converting notebook while.ipynb to python [NbConvertApp] Writing 758 bytes to while.py
if it does not work for you try, by pip3.
You can use the following script to convert jupyter notebook to Python script, or view the code directly.
To do this, write the following contents into a file
cat_ipynb
, thenchmod +x cat_ipynb
.Then you can use
cat_ipynb your_notebook.ipynb > output.py
Or show it with
vi
directlycat_ipynb your_notebook.ipynb | view -