30

I have read about .py and .ipy, also the difference between python, ipython and notebook.

But the question is: what is the real difference between .py and .ipynb file?

Is .ipynb file just more convenient to be run on jupyter notebook, or anything more? I am wondering because I am thinking about which format to be used for publishing on GitHub.

Thanks

Rifky Niyas
  • 1,737
  • 10
  • 25
Hao Xu
  • 449
  • 1
  • 5
  • 8
  • Depends on what you publish. Do you want to publish an interactive workbook for learning experience or do you want to publish a library? – Thomas Weller Aug 14 '19 at 21:52
  • https://www.sololearn.com/Discuss/2256311/what-is-the-difference-between-py-and-ipynb-extension – Channa Feb 09 '22 at 05:45

4 Answers4

25

.py is a regular python file. It's plain text and contains just your code.

.ipynb is a python notebook and it contains the notebook code, the execution results and other internal settings in a specific format. You can just run .ipynb on the jupyter environment.

Better way to understand the difference: open each file using a regular text editor like notepad (on Windows) or gedit (on Linux).

Save on git the .ipynb if you want to show the results of your script for didatic purposes, for example. But if you are going to run your code on a server, just save the .py

Rifky Niyas
  • 1,737
  • 10
  • 25
Josir
  • 1,282
  • 22
  • 35
10

py means PYthon

ipynb means Interactive PYthon NoteBook - which is now known as Jupyter notebook.

The latter one is merely a Python script with descriptive contents - you describe what your data is doing by means of Python script and some funny texts. That's pretty much it - and also, you need a specific editor e.g. PyCharm or Google Collab to open and run it.

ha9u63a7
  • 6,233
  • 16
  • 73
  • 108
7

Adding @Josir answer, the below information is very useful for open .ipynb file using PyCharm.

  1. Create a new Python project in Pycharm
  2. Specify a virtual environment, and install the jupyter package(pip install jupyterlab).
  3. Run the server using the jupyter-lab command.
  4. Browser will open the jupyter notebook like below, there you can execute the .ipynp file. enter image description here

Here is documentation https://jupyterlab.readthedocs.io/en/latest/

Sathiamoorthy
  • 8,831
  • 9
  • 65
  • 77
2

I think the answer here might help you: https://stackoverflow.com/a/32029027/11924650

.ipy indicates that it's an IPython script. The only difference between IPython scripts and normal Python scripts is that IPython scripts can use IPython magics, e.g. %timeit, and run system commands as !echo Hi.

Farrago-Alex
  • 128
  • 8