.ipynb to .py

.ipynb to .py

### Converting .ipynb to .py

Hello Techies, Welcome to my blog. In this article, we are going to know about how to convert .ipynb file to .py file. Let's get started...

First, let's try to understand the topic.

What is an .ipynb file?

ipynb is the abbrevation for interactive python notebook which is a Jupyter notebook. You might have worked with Juypter notebook which is used to write some python code. The files written in jupyter notebook will be saved with .ipynb extension. Here is how it looks like.

ipynb.PNG

You don't need to worry about this now. If you don't know, you can learn it later :)

What is a .py file?

Well, I don't thinks this needs an introduction. But let me tell you anyways. The python file which you write or create in any editor will be saved with .py extension. So the files having .py extension are python files.

Why do you need to know this conversion?

So, there is a reason why I am writing this article. I have created few files in jupyter notebook which got created with .ipynb extension. When I try to open the same files in other IDEs, the content in the file is not in a readable way. This is because the file is created in jupyter notebook. Then I started searching for a solution to this. So I came across this process.

Okay you got it. Now it's time to know the actual process.

Before we start, note that this process is simple and you don't need to code. This can be done in two ways. Excited? Ok, Scroll down.

From the Jupyter UI:

You can go to File -> Download as -> Python file

jup.png

Using Python Packages:

Prerequisites:

Installation:

Run the below commands to install the libraries.

pip install ipython
pip install nbconvert

Now, we have everything we need. Follow the below steps.

Step 1: In command prompt go to the location where your .ipynb file is located. Step 2: Run the below command.

  • To convert a single file
ipython nbconvert filename.ipynb --to script
  • To convert multiple files
ipython nbconvert file1.ipynb file2.ipynb --to script
  • To convert all files with .ipynb extension to .py
ipython nbconvert *.ipynb --to script

Well done. The files will be stored with same filenames but with .py extension in the same location.

Thanks for coming here. Happy Learning :)

Did you find this article valuable?

Support Lakshmi Sowjanya by becoming a sponsor. Any amount is appreciated!