User Tools

Site Tools


help:developer_tools:spellchecker

Jupyter UK Spellchecker

Installation

The following three lines of code needs to be run to install the basic tools for Jupyter Notebook.

Before running this shut down all running notebooks or active Jupyter sessions.

pip install jupyter_contrib_nbextensions
jupyter contrib nbextension install --user
jupyter nbextension enable spellchecker/main

The commands can be run in any Python enabled environment. Run them one at a time and look for error messages.

The spellchecker button should now appear in the notebooks, make sure it is checked on and misspelled words should now be highlighted in markup section when in edit mode in the notebooks.

Configure for UK spelling

Setting the dictionary to UK Enlish requires editing the spellchecker configuration file.

Again ensure that no notebooks are running and shut down all jupyter active sessions too before editing the configuration file.

The hints for editing this file can be found in the spellcheker git page1).

The challenge is finding this file as it gets installed in different places by various distributions. On windows pc's with Anaconda it should be in the following location:

C:\ProgramData\Anaconda3\Lib\site-packages\jupyter_contrib_nbextensions\nbextensions\spellchecker

In the folder there is a python file called download_new_dict.py.

download_new_dict.py
  1. from __future__ import print_function
  2.  
  3. import base64
  4. import os.path
  5.  
  6. from jupyter_core.paths import jupyter_data_dir
  7. from notebook.services.config import ConfigManager
  8.  
  9. try:
  10. from urllib.request import urlopen # Py3
  11. except ImportError:
  12. from urllib import urlopen # Py2
  13.  
  14. remote_base_url = (
  15. 'https://chromium.googlesource.com/' +
  16. 'chromium/deps/hunspell_dictionaries/+/master'
  17. )
  18. local_base_url = os.path.join(
  19. jupyter_data_dir(),
  20. 'nbextensions', 'spellchecker', 'typo', 'dictionaries')
  21.  
  22. lang_code = 'en_GB'
  23.  
  24. if not os.path.exists(local_base_url):
  25. print('creating directory {!r}'.format(local_base_url))
  26. os.makedirs(os.path.realpath(local_base_url))
  27.  
  28. cm = ConfigManager()
  29. for ext in ('dic', 'aff'):
  30. dict_fname = lang_code + '.' + ext
  31. remote_path = remote_base_url + '/' + dict_fname + '?format=TEXT'
  32. local_path = os.path.join(local_base_url, dict_fname)
  33. print('saving {!r}\n to {!r}'.format(remote_path, local_path))
  34. with open(local_path, 'wb') as loc_file:
  35. base64.decode(urlopen(remote_path), loc_file)
  36. rel_path = './typo/dictionaries/' + dict_fname
  37. cm.update('notebook', {'spellchecker': {ext + '_url': rel_path}})
  38.  
  39. cm.update('notebook', {'spellchecker': {'lang_code': lang_code}})

Around the middle of the file edit the language code to en_GB, save the file and run the script.

This script download the UK dictionaries locally and sets the path variables to load the files on starting the notebook.

Starting the notebook in debug mode should show the proper loading of the new dictionaries, i.e. “jupyter noebook –debug”

[D 13:30:15.266 NotebookApp] 200 GET /nbextensions/spellchecker/main.css?v=20181105133001 (127.0.0.1) 13.03ms
[D 13:30:15.281 NotebookApp] Path spellchecker\typo\dictionaries\en_GB.aff served from C:\Users\winuser\AppData\Roaming\jupyter\nbextensions\spellchecker\typo\dictionaries\en_GB.aff
[D 13:30:15.283 NotebookApp] 200 GET /nbextensions/spellchecker/typo/dictionaries/en_GB.aff?v=20181105133001 (127.0.0.1) 3.01ms
[D 13:30:15.292 NotebookApp] Path spellchecker\typo\dictionaries\en_GB.dic served from C:\Users\winuser\AppData\Roaming\jupyter\nbextensions\spellchecker\typo\dictionaries\en_GB.dic
[D 13:30:15.299 NotebookApp] Initializing websocket connection /api/kernels/da53f4c0-524a-4fdd-b28c-785112af6109/channels
help/developer_tools/spellchecker.txt · Last modified: 2020/06/20 14:39 (external edit)