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.
JavaScript
x
32
32
1
# ---
2
# jupyter:
3
# jupytext:
4
# formats: ipynb,py:light
5
# text_representation:
6
# extension: .py
7
# format_name: light
8
# format_version: '1.4'
9
# jupytext_version: 1.2.0
10
# kernelspec:
11
# display_name: Python 3
12
# language: python
13
# name: python3
14
# ---
15
16
# # Title/filename here
17
18
# ### Initialise
19
20
import pandas as pd
21
import numpy as np
22
# etc
23
24
25
# ### Title here
26
27
# +
28
do_stuff()
29
30
31
32
Advertisement
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.