converting from .py to .ipynb

Just rename it changing the extension e.g. for linux/macos

mv <file>.py <file>.ipynb

or right-click rename for windows and type the full name with the extension

(Since it seems that the contents are .ipynb contents already)


You really should consider using jupytext

Run conda install jupytext or pip install jupytext

Then do: jupytext --set-formats ipynb,py <file>.ipynb

This will create the .ipynb file and for an additional bonus keep it synchronized to the .py file:

jupytext --set-formats ipynb,py <file>.ipynb --sync

This will make sure jupyter keeps the two files in sync when saving from now on...

Last note: If you are a gui person, after running the installation command for jupytext, everything else can be done from the gui as well File-->jupytext-->pair Notebook with light Script: enter image description here


Use p2j to convert Python source code to Jupyter Notebook.

From the command line, run

-->pip install p2j

then go to the directory where your file is located. -->( for example-> cd downloads, if the file is in download directory)

then run

-->p2j myscript.py

This will create a myscript.ipynb file.