Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

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

like image 396
Hao Xu Avatar asked Aug 14 '19 21:08

Hao Xu


People also ask

Is .ipynb file a Python file?

An IPYNB file is a notebook document created by Jupyter Notebook, an interactive computational environment that helps scientists manipulate and analyze data using Python.

What is a .ipynb file?

ipynb file extension is used for computational notebooks that can be open with Jupyter Notebook. The Jupyter Notebook was formerly named IPython Notebook. The extension *. ipynb is from letters IPython Notebook. The IPython was developed as a command shell for interactive computing in Python programming language.

How do I change a .ipynb file to a .py file?

Open the jupyter notebook that you want to convert. Navigate into the 'File' menu and select 'Download as'. The more options will be displayed in the form of a list where you will click on the 'Python (. py)' option.

How do I save a Python script as .py file in Jupyter Notebook?

One way is to write the code in Jupyter notebook directly and download it as . py file. Another way is to create . py file in the text editot of Jupyter notebook and save it directly.


2 Answers

.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

like image 136
Josir Avatar answered Sep 21 '22 04:09

Josir


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/

like image 27
Sathia Avatar answered Sep 21 '22 04:09

Sathia