[PYTHON] [MEMO] [Development environment construction] Jupyter Notebook

Introduction

If you want to know more Please refer to here!

For when you are in a hurry

The following is the process from installation to activation.

Basic

For scraping

pip install -U pip && pip install wheel pandas bs4 selenium requests googletrans emoji jupyter jupyter_contrib_nbextensions jupyterthemes  && jupyter nbextensions_configurator enable --user  && mkdir -p $(jupyter --data-dir)/nbextensions  && cd $(jupyter --data-dir)/nbextensions && git clone https://github.com/lambdalisue/jupyter-vim-binding vim_binding  && chmod -R go-w vim_binding  && jupyter nbextension enable vim_binding/vim_binding 

jupyter installation

pip install jupyter

Automatic loading

Automatically reload the imported module

Type in cell and shift+enter


%load_ext autoreload
%autoreload 2

Maximize cell width

When looking at the DataFrame of pandas, if the cell width is the default, the characters will be cut off, so set the cell width to the maximum

css:~/.jupyter/custom/custom.css


.container { width:100% !important; }

jupyter-nbextension

Make extensions available

pip install jupyter_contrib_nbextensions
jupyter contrib nbextension install --user

https://github.com/ipython-contrib/jupyter_contrib_nbextensions

table of content Show list of markdown

Setting

Nbextension tab toc2 Perameter Check Display toc window / sidebar at startup

jupyter-themes

pip install jupyterthemes

https://github.com/dunovank/jupyter-themes

Added font to jupyterthemes

Get your favorite font from ~ / usr / share / fonts and create a folder with the same font name ** in fonts / monospace etc. in the jupyterthemes installation directory ** (python / site-packages / jupyterthemes / fonts / monospace / font name folder) Put the font in this folder.

jupyterthemes
   ├── fonts
   │   ├── monospace
   │   │   ├── migu
   |   |   |   ├── migu.ttf

After that, describe the font you want to add to python / site-packages / jupyterthemes / stylefx.py.

python/site-packages/jupyterthemes/fonts/monospace/stylefx.py



def stored_font_dicts(fontcode, get_all=False):
    fonts = {'mono':
            {'anka': ['Anka/Coder', 'anka-coder'],
            ........
            ........
            'ubuntu': ['Ubuntu Mono', 'ubuntu'],
            'migu': ['Migu 1M', 'migu']}, #Newly added font
            'sans':
            {'droidsans': ['Droid Sans', 'droidsans'],
            ........
            ........

set theme


#Dark system
jt -t monokai -cellw 100% -fs 15 -T -f migu

# Light system
jt -t grade3 -fs 95 -altp -tfs 11 -nfs 115 -cellw 88% -T

Figure background color (dark theme only)

There is a problem that the background color of the figure and the theme color are covered, so respecify the background color

Add to the following file

css:~/.jupyter/custom.css


div.output_area img, div.output_area svg {
 background: #fff;
}

comment color

css:~/.jupyter/custom.css


.edit_mode .cell.selected .CodeMirror-focused.cm-fat-cursor {
 /*When it's a dark theme*/
 /* background-color: #282828; */

 /*When the theme is light*/
 background-color: #fffae6;
 color: #f8f8f0;
}

.edit_mode .cell.selected .CodeMirror-focused:not(.cm-fat-cursor) {
 /*When it's a dark theme*/
 /* background-color: #282828; */

 /*When the theme is light*/
 background-color: #fffae6;
 color: #f8f8f0;
}

Vim

1. Put jupyter_contrib_nbextensions

pip install jupyter_contrib_nbextensions

2. Enable nb extensions

jupyter nbextensions_configurator enable --user

3. Create an nbextensions folder in jupyter's data directory

mkdir -p $(jupyter --data-dir)/nbextensions

4. Clone vim_binding to the nbextensions folder

If you don't have git, install it.

cd $(jupyter --data-dir)/nbextensions
git clone https://github.com/lambdalisue/jupyter-vim-binding vim_binding

5. Grant permissions to vim_binding

chmod -R go-w vim_binding

6. Enable vim

jupyter nbextension enable vim_binding/vim_binding

Successful introduction if OK


Enabling notebook extension vim_binding/vim_binding...
      - Validating: OK

7. If the theme is dark, change the background color

In the case of monokai, it would be nice to do something like # 272822.

css:~/.local/share/jupyter/nbextensions/vim_binding/vim_binding.css


...
...
...
.edit_mode .cell.selected .CodeMirror-focused.cm-fat-cursor {
  background-color: #272822;
}
.edit_mode .cell.selected .CodeMirror-focused:not(.cm-fat-cursor) {
  background-color: #272822;
}

** Maybe you don't have to set it? ?? ?? ?? ?? ?? ?? ** **

Keymap

js:~/.jupyter/custom/custom.js


// Configure CodeMirror Keymap
require([
  'nbextensions/vim_binding/vim_binding',   // depends your installation
], function() {
  // Map jj to <Esc>
  CodeMirror.Vim.map("jj", "<Esc>", "insert");
  // Swap j/k and gj/gk (Note that <Plug> mappings)
  CodeMirror.Vim.map("j", "<Plug>(vim-binding-gj)", "normal");
  CodeMirror.Vim.map("k", "<Plug>(vim-binding-gk)", "normal");
  CodeMirror.Vim.map("gj", "<Plug>(vim-binding-j)", "normal");
  CodeMirror.Vim.map("gk", "<Plug>(vim-binding-k)", "normal");
});

jupyter-vim-binding link https://github.com/lambdalisue/jupyter-vim-binding#customization

About keymap https://codemirror.net/keymap/vim.js

Shortcut

Shortcuts to remember & set at a minimum If you remember more than necessary, Vim commands will overlap, so don't worry

** Premise **

--Introduced vim-binding --How to use jupyter mode --Some shortcut keys can only be used after entering jupyter mode with Shift + Esc. --Cut cell (dd), paste (p), etc.

** Common to all modes **

** Jupyter mode only **

one thing

Well, you can remember more, but if you have a head to remember. If you don't get confused with other Editors and shortcuts, add more and more to become a jupyter master.

Recommended Posts

[MEMO] [Development environment construction] Jupyter Notebook
Django development environment construction memo
[MEMO] [Development environment construction] Python
[MEMO] [Development environment construction] wine
Jupyter Notebook memo
Jupyter Notebook memo
Emacs Python development environment construction memo
Ubuntu Desktop 20.04 development environment construction memo
Mac OS X development environment construction memo
ConoHa environment construction memo
python2.7 development environment construction
BigGorilla environment construction memo
Anaconda environment construction memo
[Memo] Django development environment
Analytical environment construction with Docker (jupyter notebook + PostgreSQL)
[Memo] Construction of cygwin environment
Anaconda3 × Pycharm environment construction memo
Ubuntu18.04 Development environment creation memo
django project development environment construction
python3.8 venv environment jupyter notebook
Development environment load measurement memo
Virtual environment construction with Docker + Flask (Python) + Jupyter notebook
Python environment construction memo on Windows 10
Jupyter Notebook essential for software development
Python memo Anaconda x Jupyter Notebook
[For beginners] Django -Development environment construction-
Easy Jupyter environment construction with Cloud9
Python environment construction memo on Mac
[Python3] Development environment construction << Windows edition >>
Star Cluster environment construction work memo
Vim + Python development environment setting memo
Development environment construction (2020 version, WSL2 + VcXsrv)
Mac OS X Mavericks 10.9.5 Development environment construction
Python3 + venv + VSCode + macOS development environment construction
Mac OS X Yosemite 10.10 Development environment construction
Construction of development environment for Choreonoid class
A memo packed with RADEX environment construction
[Jupyter Notebook memo] Display kanji with matplotlib
Windows + gVim + Poetry python development environment construction
Django environment construction
DeepIE3D environment construction
Introducing Jupyter Notebook
Linux environment construction
Python environment construction
Environment construction (python)
Powerful Jupyter Notebook
django environment construction
CodeIgniter environment construction
python environment construction
Python --Environment construction
Jupyter notebook password
Python environment construction
OpenLDAP construction memo
Golang environment construction
python environment construction
Word2vec environment construction
Browser specification of Jupyter Notebook in Windows environment
Try using conda virtual environment with Jupyter Notebook
Kotlin / Native development environment construction & installation procedure & tutorial
Mac development environment construction (Ansible + Serverspec + Travis CI)
Mac OS X Mountain Lion 10.8.5 Development environment construction