PY IPYNB
File conversion

Convert PY to IPYNB

QUICK ANSWER
Is it possible to convert PY to IPYNB?
Yes - PY converts to IPYNB.

Install jupytext with pip install jupytext and run jupytext --to notebook file.py; this produces a .ipynb file in the same folder. Add # %% markers in your .py source beforehand to control where cell boundaries fall.

Also to IPYNB: JUK

On this page

Tested on macOS, Windows & Linux
Last verified Oct 2026

More free converters

HEIC, PNG, WEBP, MP3 and more - every tool here is free.

Open the toolbox

Why convert PY to IPYNB?

Researchers and data scientists use .ipynb notebooks in JupyterLab to run code interactively, see inline plots, and add markdown explanations between code sections. Converting a plain .py script to .ipynb makes it runnable step-by-step in that environment without rewriting the code.

How to convert PY to IPYNB

jupytext OPEN-SOURCE

Run pip install jupytext then jupytext --to notebook file.py; place # %% comments in the .py source to define cell boundaries before converting for the best result.

Jupyter (nbconvert) FREE

Run jupyter nbconvert --to notebook --execute file.py to convert and run the script storing outputs in the .ipynb; omit --execute to convert without running.

About these formats

Quality & what to watch

  • Cell boundaries are guessed when no # %% markers are present - add # %% to your .py file before converting to control exactly where each cell starts.
  • The converted .ipynb contains no cell outputs; plots, print statements, and other results are generated when you run the notebook in JupyterLab.
  • nbconvert treats the entire .py as a single code cell unless the file already contains # In[]: cell markers; jupytext handles plain scripts more gracefully.

Frequently asked questions

Will my Python imports and functions work the same in the notebook?
Yes - the code is unchanged. You may need to adjust relative file paths if the notebook is in a different directory than the original script.
Can I convert the notebook back to a .py file?
Yes - jupytext supports bidirectional conversion; run jupytext --to py file.ipynb to go back to a plain Python script.
What is the difference between jupytext and nbconvert for this task?
jupytext produces better cell splits for plain scripts and respects # %% markers; nbconvert is built into Jupyter and can execute the code and store outputs during conversion.