mouwsy
mouwsy

Reputation: 1933

Convert .py to .ipynb file in pycharm

As Jupyter Notebook integration is available in PyCharm professional, is there a GUI option to convert a .py to a .ipynb file? I tried to edit the file extension, e.g. from test.py to test.ipynb, but then I can't open the .ipynb file.

Upvotes: 6

Views: 7340

Answers (3)

Renato Rocha
Renato Rocha

Reputation: 41

If all you want is just to run your code cell by cell directly on Pycharm's console, you don't need to convert it from .py to .ipynb.

Just activate View > Scientific Mode and add #%% markers to separate the cells directly in your .py file. Now you can execute it by using the green arrows on the left side of your code.

Tested on Pycharm professional 2020.3.2

Upvotes: 4

Tamlyn
Tamlyn

Reputation: 23562

Simplest way I found without installing extra dependencies is:

  1. Create a new notebook: File > New > Jupyter notebook
  2. Copy and paste the Python code into it

Then you can add #%% markers to separate the cells.

Upvotes: 3

Related Questions