Hao Xu
Hao Xu

Reputation: 637

What is the difference between a .py file and .ipynb file?

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

Upvotes: 48

Views: 120785

Answers (4)

Josir
Josir

Reputation: 1644

.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

Upvotes: 53

Sathiamoorthy
Sathiamoorthy

Reputation: 11600

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/

Upvotes: 10

ha9u63a7
ha9u63a7

Reputation: 6854

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.

Upvotes: 20

Farrago-Alex
Farrago-Alex

Reputation: 120

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.

Upvotes: -2

Related Questions