6

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.

mouwsy
  • 1,457
  • 12
  • 20

3 Answers3

3

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

2

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.

Tamlyn
  • 22,122
  • 12
  • 111
  • 127
1

Try using

pip install ipynb-py-convert

https://medium.com/@researchplex/the-easiest-way-to-convert-jupyter-ipynb-to-python-py-912e39f16917

  • Thank you, but I asked for a GUI option for conversion. I mean something you can set in the PyCharm IDE user interface. – mouwsy Dec 13 '20 at 10:37
  • I see well I personally stopped using PyCharm because it's not as universal. VS Code has easier accessibility for it(but of course you have to choose your preferd IDE and accept possible drawbacks). https://code.visualstudio.com/docs/python/jupyter-support – Richard Taujenis Dec 13 '20 at 10:51