Jupyterlab: turn on tab completion for text editor as in Notebook? - jupyter-notebook

In Jupyterlab, there is a text editor that we can open .py files, is it possible to also turn on tab completion, just like how it works in Notebook ?

By now, tab completion in the text editor of jupyter lab has been implemented in this pull request (see also discussion in this issue). However, for it to be working you need to open a console for the editor (right click in the editor window and select Create Console for Editor).

No, it is currently an open issue. https://github.com/jupyterlab/jupyterlab/issues/1276

The package jupyterlab-lsp now provides tab completion in the text editor. You need can install it from pip or conda, along with a language server for Python:
pip install jupyter-lsp
pip install jedi-language-server
I also needed to enable the server side extension:
jupyter server extension enable --user --py jupyter_lsp
And enabled #krassowski/jupyterlab-lsp and #krassowski/completion-theme via JupyterLab's extension GUI (the puzzle piece on the right hand side). Then I restarted JupyterLab, and completion worked (with Tab). I am not sure if all these steps are neccessary, it might depend on your environment.

Related

Some setting changes in Table of Contents 2 (toc2) in nbextensions not showing up in Jupyter notebook I had open at the time of installation

I recently installed nbextensions in my conda environment to add the ability to add a Table of Contents (toc2) to my notebooks. But I did this while having a jupyter notebook open and after installing the extension, changes in the extension settings didn't reflect on the notebook I had open during installation while it did on the others that weren't.
I tried shutting down and restarting the kernel, restarting the computer, and uninstalling and re-installing nbextensions again (following these instructions on a github ticket). None of these things rectified the issue with the notebook that was open. A duplicate of the notebook inherits its problems.
An interesting thing to note is that after reinstalling nbextensions, which was my last attempt, changes of the settings from the first install were held over instead of going back to default (ie color settings in nbextensions being the distinct colors I had switched them to before the uninstall). I'm not sure if I fully uninstalled nbextensions or if it's really possible. And after the re-install, further changes in the settings in the second go-around didn't reflect on any notebooks afterwards, like removing the sidebar toc setting after selecting it the first time, the sidebar remains in certain notebooks.
I'm not sure what's going on but:
1.) Is there a way to get the settings changes to reflect on the notebook universally, particularly having a toc? Especially on the notebook that was open at the time of install?
2.) Is there a way to totally un-install nbextensions like it never existed on my machine so I can try this again?
Step 0 - Is this a problem with the Notebook metadata?
The toc2 module adds some metadata to the notebook.
Just in case this metadata is missing, has wrong values, or the defaults written make the ToC does not show up try this:
Open the notebook and select "Edit"->"Edit Notebook Metadata".
Remove the "toc":section if it exists an add this to the end of the metadata:
"toc": {
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"base_numbering": 1,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": true,
"toc_position": {
"height": "382px",
"width": "256px",
"left": "10px",
"top": "10px"
},
"toc_section_display": true,
"toc_window_display": true
}
Be careful not to remove any comma(,) after the closing } if exists ! This must be a valid JSON file.
After changing the metadata:
Clic on the "Edit" button
Save the notebook
Close the browser window
Annd open the notebook again.
You should see a floating TOC window.
If not, go to the next step.
Step 1 - Is this a Jupyter problem?
Check the jupyter_contrib_nbextensions is installed (pip freeze | grep jupyter_contrib_nbextensions).
Open jupyter and check there is a 'Nbextensions' tab next to the 'Clusters' tab on the home page.
Open the 'Nbclusters' tab and leave unchecked the ' disable configuration for nbextensions without explicit compatibility (they may break your notebook environment, but can be useful to show for nbextension development)' box.
Now look for the 'Table of contents (2)' extension and enable it.
Now your should see the TOC when you open the notebook.
If not, go to the next step.
Step 2 - Is this a browser-related problem?
Looking at the toc2 extension soure we can see this is client-based based on Javascript code.
When you load the Jupyter notebook, the module main.js is added to the .js your browser runs and modifies some menu commands.
To discard we have caching issues, open Jupyter using with a 'fresh' browser.
This could be either:
Another browser (chrome, firefox, Edge..)
Or your 'normal' browser in incognito/InPrivate mode
With a 'clean' browser you should be able to open the notebook and see the navigation bar from the TOC extension.
What to do now:
If the Clean browser works, but the "normal" browser doesn't
clear cache in the normal browser and try again.
If the Clean browser does not work and Jupyter is running on your local machine.
We've hit a bug here.
Open your browser developer tools, open a ticket in github, and add the console output from developer tools.
If the Clear browser does not work and Jupyter is running on a remote machine
Do you use a proxy? or is your ISP using transparent caching for this page/parts of the page (last one is hard to assess).
Try running Jupyter in another port (with the --port option). That should fix he problem. Consider using https instead of http to avoid caching by intermediate network.

How can I disable the autocomplete function in Jupyter notebook(Tab)

I typed "Summary" outside the cell and change the config of Jupyter notebook.
When I press Tab, the autocomplete menu pop out, but I only want 4 spaces when I press Tab. I Google this question and try something like:
%config IPCompleter.greedy=False
However, I still have the autocomplete menu when I press Tab. How can I disable it?
There is an extension called 'Hinterland' for jupyter, which automatically displays the drop down menu when typing or control when it should appears . There are also some other useful extensions.
In order to install extensions, you can follow the guide on this Github repository . To easily activate extensions, you may want to use the extensions configurator.
To install Hinterland run in a Conda terminal this:
conda install -c conda-forge jupyter_nbextensions_configurator
To enable it :
jupyter nbextension enable hinterland/hinterland

Can't use IPython console in PyCharm

I wanted to use ipython as default console in Pycharm but it doesn't work.
I have selected use ipython when available in the console option available under Build,Deployment and Execution in Settings. Did the same in Default Settings also. But it doesn't seem to work.
I am using Python 3.6.3 , IPython 6.2.1 and PyCharm Professional 2017.3
This is probably because IPython is not recognized as a package in your project interpreter.
This usually happens when you configure a virtualenv for your project, but don't check the Inherit global site-packages checkbox.
Fixing is quite easy:
Go to Settings -> Project: <project name> -> Project interpreter
At the bottom of the packages list you should see a + sign.
Press that button, find ipython and install it.
On the next time you'll open your console, IPython will be detected and used automatically.
You have not installed IPython package.
Do this:
              File → Settings... → Project your_project → Python Interpreter
then click the + button on the right-hand vertical toolbar (see the red arrow in the picture):
and from the new popup window select and install ipython package:
Finally, restart your Python Console.

Atom editor opens to empty window and dev tools

I installed a buggy package in Atom which has been crashing the editor repeatedly. So, I went into Atom Settings to remove it, but just out of curiousity I clicked the "Open Config Folder" button beforehand which opened an empty window and dev tools alongside:
Atom subsequently crashed (probably because of the buggy package I was about to install) and now when I open Atom, I only see the above window and nothing else, even if I open it from the "Open with Atom" context menu from any folder. So, now I'm stuck with just this window and no actual Atom Editor.
I tried re-installing Atom and it did not solve the issue. I checked the "Atom" menu available in that window and it only gives me basic options: "Check for Update", "Reload", "Close Window", "Toggle Dev Tools", and "Quit", none of which can get me back to the main editor window.
Anybody seen this before or know how to break out of it?
I got the same problem but on Ubuntu. I tried apt-get --reinstall and purge but both did not work.
Turns out it was just no read permissions for /home/username/.atom/
All I did to fix it was:
sudo chmod 777 -R '/home/username/.atom'
I found a quick solution for this. The Atom uses a BLOB file to store data from the last user session and re-open that when Atom is restarted. By removing that file, Atom restarted at it's default state.
You can find that file on a Windows machine here:
C:\Users\[Username]\.atom\blob-store
Just delete, or rename, the file BLOB. Then, just open up Atom and you should be good to go.
Try this:
Close Atom
Remove C:\Users\[Username]\.atom\storage\application.json
Start Atom

What happened to the TOC extension for ipython notebook?

I'm trying to install the great table of contents extension in a new computer. but I cant find it anymore. the only page I do find does not explain how to install the extension on windows.
So.. How can I install it, and why is it not a part of the official Ipython notebook? I simply can't understand how people are getting along without it.
I've installed toc nbextension successfully with Jupyter 4 (ie. ipython notebook 4) recently.
In fact installing extension is easier than before :)
I post my solution here, may it help.
## download
mkdir toc
cd toc
wget https://raw.githubusercontent.com/minrk/ipython_extensions/master/nbextensions/toc.js
wget https://raw.githubusercontent.com/minrk/ipython_extensions/master/nbextensions/toc.css
## install and enable
cd ..
jupyter-nbextension install --user toc
jupyter-nbextension enable toc/toc
A bit more explain:
install will copy toc to ~/.local/share/jupyter/nbextensions/
enable will modify ~/.jupyter/nbconfig/notebook.json.
You can check these two place to see what happened.
Note: we use enable toc/toc here is because toc.js is in ~/.local/share/jupyter/nbextensions/toc/.
If you put toc.js and toc.css directly in ~/.local/share/jupyter/nbextensions/ then you should use enable toc here.
Edit
Sorry, I didn't notice the orginal problem is on windows. I'm not sure if it's same for windows jupyter, any report is welcome.
Update
Now the toc nbextension has been added into this project which provide a collection of kinds of nbextensions. It's very easy to install and manage, worth to try!
I cannot tell you specific Windows advice, but think the key points should be platform independent:
Create a profile (either a default profile or a named one - you'll probably want default to start).
Locate where the profile is.
Add the custom.js file into the profile.
Edit the custom.js file to point to the notebook extension code.
In a bit more detail, setting up a profile is covered in detail here but for a default profile just go to the command line and enter
ipython profile
Next, locate where your profile is stored by typing at the command line
ipython locate
Call that <profile_dir>.
The rest follows the (Windows equivalent of!) the instructions on the link you have: underneath <profile_dir> navigate to (creating any directories that do not already exist)
<profile_dir>/static/custom/
and add the custom.js file as shown. Then edit the first line, where it has "nbextensions/toc" to point to the location where you have placed the toc.js file you have downloaded. This location is relative to the <profile_dir>; for me I have
<profile_dir>/static/custom/custom.js
<profile_dir>/static/custom/nbextensions/toc.js
<profile_dir>/static/custom/nbextensions/toc.css
and the first line of custom.js reads
require(["/static/custom/nbextensions/toc.js"], function (toc) {
Finally, note that this is with version 1.1.0 of the notebook - if you're using an earlier version I strongly suggest you upgrade before trying this.
You'll also find the official installation instructions at:
https://github.com/minrk/ipython_extensions
These instructions include curl commands for retrieving the toc.js and toc.css files from GitHub, which worked fine for me in a bash shell on linux Mint.
For Windows 7, I used a Git Shell (see http://msysgit.github.io/) to execute the curl commands
This IPython Notebook semi-automatically generates the files for minrk's table of contents in Windows. It does not use the 'curl'-commands or links, but writes the *.js and *.css files directly into your IPython Notebook-profile-directory.
There is a section in the notebook called 'What you need to do' - follow it and have a nice floating table of contents : )
Here is an html version which already shows it:
http://htmlpreview.github.io/?https://github.com/ahambi/140824-TOC/blob/master/A%20floating%20table%20of%20contents.htm

Resources