How to run .py codes on jupyter lab?

Viewed 8103

How can I run .py files from jupyter lab? I have spent my all coding life using jupyter notebook and jupyter lab but replication codes of research papers are mostly in .py file format

For instance, this is a github repository for beta variational autoencoder. As you can see from the repository, these kinds of repositories are usually comprised of main.py, model.py, which looks a lot different from .ipynb format that I usually use.

Can someone share how to comfortably run these kinds of .py codeson jupyter lab? I would appreciate it a lot if someone tells me a video or an article explaining how to run these .py codes on jupyter lab comfortably.

3 Answers

"...how to run these .py codes on jupyter lab comfortably."

Basically the Jupyter's IPython interface allows you to do magic commands that commands within a shell.

Here is the magic for python subprocess.

You can use:

%python -m /path/to/myfile

Then execute the cell and the command will run in the cell and the output cell is the standard output for this run. You can also make this run in tmux or other tools to make it as a managed background job.

Find File-> new launcher -> other -> terminal, then you use command line run your python file, like "python xxx.py"

Related