Converting .py files to .ipynb

4.1k Views Asked by At

My organisation converts any Jupyter Notebooks (.ipynb files) it makes into python scripts (.py files) for easier management in our repos. I need to convert them back so I can run the notebooks but can't work out how.

I believe they've been encoded using the nbconvert package but I couldn't find a way to convert the files back in the package docs.

I've included the head of one of the .py files bellow in case it makes the encoding format more obvious.

# ---
# jupyter:
#   jupytext:
#     formats: ipynb,py:light
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.4'
#       jupytext_version: 1.2.0
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # Title/filename here

# ### Initialise

import pandas as pd
import numpy as np
# etc


# ### Title here

# + 
do_stuff()



1

There are 1 best solutions below

1
On BEST ANSWER

Looks like the file was actually converted using program jupytext.

To convert it back I found running jupytext --to ipynb my_file.py worked.

More simply: opening the .py file in jupyter notebook allowed me to view the .py file as if it were a .ipynb file without converting.