Two ways to convert ipynb file to py file

Project scenario and problem description:

Many projects on GitHub are in the .ipynb format. If you don’t use jupyter notebook to open it, use pycharm to open it, you will see cells one by one, and it is not convenient to see the code logic; or open it through jupyter notebook, but run, modify, and save in the middle The process is inconvenient. If you want to convert it to a .py file, the following two methods are provided to convert the ipynb file into a py file.
pycharm opens ipynb file


solution:

Method 1: Convert by terminal command
If you want to xxx.ipynbconvert a file to xxx.pya file, open the terminal, and execute the command in the directory where the xxx.ipynb file is located:

jupyter nbconvert --to script xxx.ipynb 

After execution, xxx.pythe file will appear in the xxx.ipynbsame directory as .

If you need to convert all ipynb files in the directory to py files, you can execute the following command:

jupyter nbconvert --to script *.ipynb

Method 2: Open jupyter notebook and save it as a .py file
After opening it with jupyter notebook, select the upper left corner File, Download as, and select Python(.py)to save it as a .py file, as shown in the figure below.
After the jupyter notebook is opened, it is saved as a .py file

Guess you like

Origin blog.csdn.net/qq_39691492/article/details/127731821