简体   繁体   中英

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, eg from test.py to test.ipynb, but then I can't open the.ipynb file.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM