Open jupyter notebook from .py in pycharm - jupyter-notebook

I am using Pycharm 2021.2.3 pro.
Is it possible to open a .py file as a jupyter notebook from within pycharm?
In the classical jupyter notebook, it is possible to open a .py file as a notebook and work with it like with a classical .ipynb (adding markdown etc.).
This allows to work on the full notebook without worrying about cells ordering like with a classical python script. When the script is ready, it is then possible to switch to the notebook view with its nice presentation features.

we did this when creating dash apps, you make the .py file upload and refer to it by way of importing as we do with regular python libraries

Related

Jupyter notebook: run code of exported file (e.g. HTML)

I wonder if it is possible to run code in an exported HTML file by "jupyter" notebook?
I am trying to make an online website for a tutorial of PariGP

How to make Jupyter lab recognize a file as notebook that is not .ipynb?

I added kernels for Julia and Haskell in Jupyter lab, however the filename extension for which is still ipynb, and I really like to distinguish them from IPython notebook.
I renamed them as *.ijlnb or *.ihsnb however Jupyter lab no longer recognizes them as notebooks but a plain text.
How to assosiate .ijlnb or .ihsnb file to Jupyter?

JuliaPro: import Jupiter notebook

I usually use Jupyter to have my interactive environment with Julia, now I am switching to JuliaPro, as they claim it is the fastest and easiest way of Julia programming. But, I cannot upload my .ipynb notebooks on JuliaPro. Are they compatible with each other? How can I work with my notebooks on JuliaPro? Thanks!
As was explained in the comments, the .ipynb file format was designed to be rendered in a browser, while Juno/Atom is a text editor that expects a plain text file for display. In general therefore you wouldn't be able to directly use an .ipynb file in Juno.
There is however an option to convert your notebooks to .jl scripts, which is exactly what Juno is expecting: in your Jupyter notebook click on File > Download as > Julia (.jl) (see below)
There's also an answer here that discusses a command line option if you need to batch convert a lot of files.
Also note that your choice of editor / programming environment is unrelated to the version of Julia you're using - while JuliaPro ships with Juno as standard (or potentially the Julia VS Code extension in future), nothing's keeping you from just doing using Pkg; Pkg.add("IJulia"); using IJulia; notebook() in your JuliaPro installation and continuing to work on your notebooks in Jupyter.

How can i edit jupyter notebook from terminal without opening web browser?

How can I edit my jupyter notebook in terminal.
I just don't like to open jupyter notebook in web browser.
I google out but every answer is related to how can we open notebook from terminal directly.
I'd suggest looking at Jupytext's ability to do command line conversions back-and-forth from the notebook json structure to a python script (or markdown). If you already have the backbone of a notebook (.ipynb) file, you can convert it to .py script using jupytext --to py notebook.ipynb. That makes a text file that is easy to edit in your favorite terminal based text editor. The json in the .ipynb files is not as easy to edit directly.
Then when you are done editing, you can convert the .py script form back to a notebook with something like jupytext --to notebook notebook.py. Optionally, you can even execute it without opening a browser by adding --execute. I have an example conversion-and-execution command in use here.

Cannot import .py file to ipython notebook

With apologies in advance for the "I can't get it to work" question: How should I load a .py file into ipython notebook? I want to convert python code to notebooks (first simple scripts and later scripts that include nbconvert directives embedded as comments-- see bottom of the linked file.)
Perhaps I'm doing it wrong, but perhaps there's something wrong with my set-up. When I drag a .py file to the Notebook's file list, I get the message
Invalid file type: Uploaded notebooks must be .ipynb files.
I even tried changing the extension to .ipynb (keeping the python script unmodified); reasonably enough, I got an error:
Error loading notebook: Bad request
Any idea what's going wrong?
System information: I'm on OS X (10.8, Mountain Lion), using Firefox 28.0 and Anaconda 1.9.2 (x86_64), which supplies python 2.7.6 and ipython 2.0. Anaconda is not on the default PATH; I add it in a bash session from which I then launch notebook with ipython notebook, and I'm able to open and edit .ipynb files normally in the browser.
But I do get some curious behavior:
When exporting from notebook as a .py file, I don't get the control comments documented here but a simpler format, without version number:
# coding: utf-8
# In[ ]:
print "This is a slide"
## Top-level title
### Second-level heading
#### Third-level heading
# This is some `markdown` text.
#
# And some more here.
Any idea what's going on here?
The same format is generated by ipython nbconvert. However, if I start the notebook server with ipython notebook --script (which exports the notebook as a python script every time it is saved), the result contains the nbconvert directives we need to convert back to a notebook!
I had the same problem.
This post helped:
How to load/edit/run/save text files (.py) into an IPython notebook cell?
Basically, we just have to use the following command in the cell. And the .py file has to be in the same directory.
%load filename.py
I'm not sure why notebook doesn't support this natively, but I've concluded that the answer is: It can't be done from the command line or notebook GUI.
Control comments like <markdowncell> can only be interpreted by accessing notebook's API through python, as shown by #CliffordVienna in this answer to my related question.
import IPython.nbformat.current as nbf
nb = nbf.read(open('test.py', 'r'), 'py')
nbf.write(nb, open('test.ipynb', 'w'), 'ipynb')
Edit: The above method does not work with the current version (v4) of the Notebook API, so I have added this self-answer to show how it's done.
If you only need to import a local file, first use:
sys.path.append(os.getcwd())
to place the .pynb file's directory in sys.path, and then import the local file.

Resources