Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to interpret .py files as jupyter notebooks

I am using an online jupyter notebook that is somehow configured to read all .py files as jupyter notebook files: n

I am a big fan of this setup and would like to use it everywhere. On my own jupyter installation however, .py files are just interpreted as test files and are not by default loaded into jupyter cells. How can I achieve the same configuration for my jupyter notebook?

like image 677
TheMP Avatar asked May 20 '20 16:05

TheMP


People also ask

How do I read a .py file in Jupyter Notebook?

load python file in jupyter notebook A text file can be loaded in a notebook cell with the magic command %load. the content of filename.py will be loaded in the next cell. You can edit and execute it as usual.


Video Answer


2 Answers

What you're looking for is jupytext. You just need to install it into python env from which you're running your jupyter notebooks:

pip install jupytext --upgrade

And you get this:
enter image description here

like image 145
Karol Żak Avatar answered Oct 22 '22 00:10

Karol Żak


That's not exactly what you asked, but you can achieve something close to that by using the magic %load FILE.py in a new jupyter notebook.

%load FILE.py will copy the contents of FILE.py in the current cell upon executing it.

like image 36
Johannes Ackermann Avatar answered Oct 21 '22 23:10

Johannes Ackermann