How to get indentation lines in Jupyter Lab/Jupyter Notebook? - python

How can I add Indentation lines like what is shown above in Jupyter Lab/Notebook?
I have tried a lot and went into the settings (not much as I am a beginner and I don't know most of the stuff) but in Jupyter I can only get code numbers from the View button but not these beautiful lines which help a lot when doing the indentation.

The default editor used by Jupyter Notebook and JupyterLab (CodeMirror) does not support indentation markers as for today; it is possible to extend it with an add-on but it seems that there isn't one yet (see Indentation Markers with CodeMirror). I imagine that you would need to create a custom overlay mode to make it work, and it might be in scope for jupyterlab-lsp extension if you would like to suggest this via issue on GitHub.
JupyterLab also allows to use a different editor via extension (and there was a proof-of-concept for that) but I don't think that anyone volunteered to maintain any other editor integration recently.
In the near future JupyterLab will likely migrate CodeMirror 6, and depending on availability of such feature in it it will either have a support for it or not. Or maybe someone will contribute a support for it to an extension. It might turn out to be easier to implement in CM6.

Related

intellisense vscode not showing parameters nor documentation when hovering above with mouse

I'm trying to migrate my entire workflow from eclipse and jupyter notebook all over to VS Code. I installed the python extension, which should come with Intellisense, but it only worse partly. I get suggestions after typing a period, but don't get any information on parameters nor documentation when hovering over with my mouse. Thank you so much for your help and have a wonderful new year!
P.S If anyone has any experience with using anaconda environments with VS Code, that would be greatly appreciated as well as I running into some problems with it recognizing the libraries.
Also you can see here that when I manually activate Intellisense, it doesn't recognize that it's in a method.
Sorry for the long string of edits, but I discovered that when typing print in a regular python file, it works, but not in a jupyter notebook file. Also, it still doesn't work for numpy. Thanks for the help everyone.
You could use the shortcut key "Ctrl+Space" to open the suggested options:
In addition, it is recommended that you use the extension "Pylance", which works better with the extension "Python".
Update:
Currently in VSCode, the "IntelliSense" document content is provided by the Python language service, which is mainly for Python files (".py" files call this function), while in Jupyter, the "IntelliSense" used by the ".ipynb" file comes from the extension "Jupyter". You could refer to the content of this link to use VS code insiders, and its notebook editor has better intellisense.
In VS code insiders:

VSCODE - PYTHON - Pandas DataFrame - Intellisense doesn't show Attributes/methods of the object

After importing Pandas, when creating a pandas dataframe, Intellisense doesn't show the available attributes/methods of the created object.(Image 2, where I try to use the .head() function).
It detects the module pd(pandas) methods without any problem (see Image 1).
I don't have this problem when running a Jupyter Notebook or Jupyter Lab on the browser.
I'm using:
Windows 7
Python 3.8.3 in a Conda environment.
VSCODE 1.46.1
Python extension 2020.6.90262
Microsoft Language Server
Visual Studio Intellicode 1.2.8
IMAGE 1: It uses intellisense to detect the module methods/attributes
IMAGE 2: Intellisense doesn't show the pandas object available attributes/methods
The detection isn't working because IntelliSense has a hard time with pandas (and pandas.read_csv() especially). It works in Jupyter because it's accessing the live data while IntelliSense has to infer everything from the source code statically.
I would advise trying out Pylance as it's the new language server from Microsoft and we have tried to support pandas appropriately. If Pylance doesn't work then
try different values for your python.languageServer setting and see which one gives you the best result.
Go to your VS Code explorer and open that folder you are currently working in. This should solve the problem. Or go to file-> Open Folder. You can also open your current working folder by hotkey ctrl + o .
Close but no cigar. In 2021, language servers still often break. I think VS code is a good idea but sometimes they just break things. I use Intellij for work and it is heavier but better in that regard. I'm sure they will get it right eventually but sadly i don't think they are taking it as serious as they should since data scientists are a big part of their costumers and if you create a pandas object you might be working with its methods for a while rather than direct methods off the modules! So it REALLY helps if we can access lets say pandas.DataFrame.groupby for example rather than just things directly after pandas alone. I keep using VS code as I like keeping my browser up and really enjoy the advantages of having an unified place to keep my python, R and notebook code :) We just need to be patient!

What's the advantage of Jupyter notebooks over any other setup where an editor is linked to a terminal

I read and heard a lot about Jupyter notebooks recently. I gave them a try and found it terribly obstructing to basically have to use an editor with the functionality of Windows' Notepad. Besides that I feel like I didn't get the fundamental point of Jupyter notebooks:
Can I not achieve everything that Jupyter does by editing plain .py files in any editor that is linked to a Python/IPython console? Specifically, I can edit Python code and run parts of it using the standard Spyder setup
or even with a properly setup Vim or Emacs.
The big difference being of course that any of these three setups gives me incredibly much more power to do all the other things that facilitate coding, like fast editing commands, code completion, debugging, refactoring, ...
You can save results and graphs of your runs like a report.
And it is better readable.
It is very good to share your results with others.

Mix python output and markdown in jupyter

I want to be able to show the result of a python computation and have some explanation of it in Markdown. This seems like a fairly simple operation, but I can't figure out how to do it.
Is there any way to do this without installing any extensions to Jupyter?
In the toolbar (see image here http://jupyter-notebook.readthedocs.io/en/latest/_images/jupyter-notebook-default.png), you can set the cell as Markdown in the drop down menu for explanatory text.
Would it suffice if you yourself didn't have to personally handle the installations to Jupyter?
I know OP says specifically, without installing an extension, but what is described is addressed with the Python-Markdown extension, see here. And this question comes up at the top of the list when one Googles "jupyter mix markdown and python print cell".
You can easily use Python-Markdown in an active notebook launched via the MyBinder system from here; the repo for that is here if you want to fork it and further adapt it by adding your own notebooks.

Scientific Reporting in Python

I am working on a scientific python project performing a bunch of computations generating a lot of data.
The problem comes when reports have to be generated from these data, with images embedded (mostly computed with matplotlib). I'd like to use a python module or tool to be able to describe the reports and "build" HTML pages for these reports (or any format supported by a browser).
I was thinking about generating an ipython notebook but I was unable to find if there is a way to do so (except creating the json but I'm doubtful about this approach).
The other way is using Sphinx a bit like the matplotlib but I am not sure how I could really fine-tune the layouts of my various pages.
The last option is to use jinja2 templates (or django-templates or any template engine working) and embed matplotlib code inside.
I know it's vague but was unable to find any kind of reference.
nbconvert has been merged into IPython itself, so please do not use the standalone version anymore. It is now fully template base so you can change things from just tweeking the css, fully re-wrote your templates, or just overwrite the current part of templates you want.
Notebook format is a pure json file, is takes ~20 lines to write a program that loop through it and re-run the codecell. That plus command line argument it is not hard to write a notebook, make it a 'template' notebook and run it on multiple dataset without opening a browser.
Some resources :
programatically run nbconvert, and run a notebook headless (first link)
I think you want to work in ipython notebook and then use nbconvert
Currently, this is it's own utility, that already works (albeit with some installation hurdles, but working) but it is currently being implemented directly into the ipython notebook machinery, which I believe should be released in autumn, or so.
The goal is (and Fernando Perez has demonstrated that this works), that a notebook becomes a fully documented, image containing pdf-document after the conversion.
Using the inline-modus of ipython notebook,
ipython notebook --pylab inline
you can execute your matplotlib-scripts in a browser interactively (thus generating your plots). Then go to
File -> Print View (in the notebook-menu, NOT the browser menu)
and save the generated html-File (via the browser menu). This will include all the plots you generated before as well as the python code. Of course, you cannot modify these html-Files anymore without the notebook-server in the background.
Is this what you mean?
I just found this old question and want to add PWeave to the list, which is perfectly suited to generate reports from python code / jupyter notebooks. I use it to share my work with colleagues that aren't invested with programming alot.
It also integrates into Spyder, THE scientific IDE for python, using the spyder-reports module.

Categories

Resources