Python code is not syntax highlighted in Pycharm notebook? - python

In the screenshot we see a pretty normal-ish python code cell within the Pycharm notebook viewer The viewer "understands" the notebook: it is bringing up the managed Jupyter server option and knows this is [python] code:
So then where did the syntax highlighting go to? How can it be [re-]enabled ?

#Wayne was headed the right direction: that link he provided Wrong Code Highlighting in Jupyter Notebooks had suggestion to reload the python interpreter.
Well in my case the interpreter is Synapse Pyspark and is grayed out since i'm presently running locally. I need to figure out how to change the interpreter: will update here at that point.
Update I needed to edit the json source of the ipynb file to find and remove the synapse kernel.

Related

How to hide Code in Jupyter Notebook w/ VS Code?

I'm using VS Code to write Jupyter notebook as I feel more comfortable with it. I found out that there is no option to edit meta data of the cells in order to hide only select code cells. I also came across some answers suggesting to use # #hidden_cell in the code cell but that doesn't work or am I doing it wrong? not much information was available for this.
I tried using the command
jupyter nbconvert my_notebook.ipynb --no-input --to pdf
and that works fine but it removes all the code. I wish to remove only specific code cells.
You can use .env to hide the code.
hidden_code = (code)
Then use the variable hidden_code inside brackets to use it.

PyCharm-like console in Visual Code Studio

I wanted to give VSC a try for developing some Python programs, where I only used PyCharm before. One of the most helpful features for me in Pycharm was the PyDev Console, where I can quickly try small snippets of code (think 3-10 lines), and adjust it to work the way I want it to.
I see VSC has a console, but it's much more like the regular IDLE console, where it's kind of hard to write these snippets of code (fixing something 2 lines prior for example is pretty much impossible).
I've been searching for an extension that'll give me a PyCharm-like console experience in VSC, but have been unable to find one. Is is out there? Or is there another way to get to the same result (like setting up a custom console based on the same PyDev console)?
Have you tried Jupyter Notebook and Interactive? There are provided by the Jupyter Extension which is bound with Python Extension.
Open the Command Palette (Ctrl+Shift+P), with the command of:
Jupyter: Create New Blank Notebook
Jupyter: Create Interactive Window
You can refer to the official docs for more details.

How to work with .ipynb files without launching the Jupyter Notebook server?

I'm starting to work more with Jupyter notebooks, and am really starting to like it. However, I find it difficult to use it with my particular setup.
I have a workstation for running all the notebooks, but for a large part of my day I'm on-the-go with a space-constrained laptop with no power outlets. I'd like to be able to edit (but not run) these notebooks without installing and running the full Jupyter server backend, which I imagine would suck up a lot of power.
My question is: Is it possible for me to edit (and not run) notebooks without running the Jupyter server?
You could use one of the following options
1. ipynb-py-convert
With this module you can do a conversion from .py to .ipynb and vice-versa:
ipynb-py-convert ~/name_of_notebook.ipynb ~/name_of_notebook.py
where according to the documentation the cells are left as they are. To get back a jupyter notebook
ipynb-py-convert ~/name_of_notebook.py ~/name_of_notebook.ipynb
2. Ipython
However, you could also do a conversion to .py when you want to work it with an editor like VS Code or Sublime Text after you have download your .ipynb file with ipython:
ipython nbconvert --to python name_of_your_notebook.ipynb
As I was asking this question, I had opened the notebook locally in Visual Studio Code, but the preview was just the raw text representation of the notebook, so I had assumed that it needed the backend to run.
However, I was about to press submit on the question when I checked back in on it, and the notebook showed up just fine. So one solution is to open it in VS Code and wait a little bit.

Unable to display image file in Jupyter markdown cell in vscode or pycharm?

This code in a Markdown cell:
<img src="images/grad_summary.png" style="width:600px;height:300px;">
works fine in Jupyter browser, but in VS Code and pycharm with Python extension it does not render at all, only a blank image box is shown. Both are running in the same conda environment.
This alternate method in a Markdown cell:
![title](images/grad_summary.png)
also works fine in Jupyter browser but does not render in VS Code with Python ext.
I searched stack overflow, there was something close but it did not address this issue. Any insights appreciated.
vocode broken image
We actually have an issue already reported with loading and showing local images. If you want to track our progress on fixing this issue you can follow our github issue here.
https://github.com/microsoft/vscode-python/issues/7704

PyCharm & Jupyter Notebook - Where's the output?

This is my first effort to run a Pycharm Jupyter Notebook project.
1) Create a project MyPythonProject. Done!
2) Create a new MyJupyterNotebook. Done!
3) Enter print('hello') into the triangular cell. Press the green run button!
Dialog appears saying please enter JupyterNotebook URL and Auth token)
4) Fair enough I go to command prompt type > Jupyter Notebook
carefully record it
http://localhost:8888=/?token=4e209a6963b8dab232c0b03379d5321431726df7713c53e0
5) Enter it into the little black dialog box!
6) Seems to connect no error BUT, no feedback. In fact I can put junk in the cell like #$#$$%#$##! in the cell and still see no output at all.
So where is my output going? I don't see this notebook after connecting to it? I don't see any results anywhere in PyCharm for executing the cell. For example I put junk in the cell and saw no output or errors anywhere in pycharm. I also put
print('hello world')
(sic) and saw no output.
I also don't see this Notebook has been loaded from PyCharm. And I wonder exactly how I would go about resetting the token if needed since the dialog just grabbed it I suppose its in project settings somewhere ... I am sure I am missing something but really thought I would see some type of output at this point when I run a cell. Any ideas what's wrong?
Update: I did load the notebook using file explorer in browser of Jupyter Notebook outside pycharm and I again see the contents of the file. But still not seeing any output in pycharm
Update: jupyter notebook keeps CONNECTING TO KERNEL
Seems like latest tornado version is not working as answered above.
There is a separate view for viewing output from cells in the top right. Just below the file tabs.

Categories

Resources