Jupyter notes
From raju
list current notebooks
jupyter notebook list
tags | list current servers
kill notebooks
jupyter notebook stop 8888
tags | kill servers
keyboard shortcuts
- comment out block of code - ctrl + /
- Block unindent - ctrl + [
- Block indent - ctrl + ]
start server
# cd to a top level directory containing all the notebooks # Activate the environment if necessary jupyter notebook
start server in a different conda environment
To start the jupyter notebook in a different environment
source activate foo jupyter notebook ctrl-c
features missing
aka things I have to figure out
- move cells up and down using mouse
useful links
- To run python3 interpreter in jupyter - https://stackoverflow.com/questions/28831854/how-do-i-add-python3-kernel-to-jupyter-ipython
- writing a post save hook to automatically save notebooks in script format - https://stackoverflow.com/a/25765194/6305733
select multiple cells
Use keyboard and not mouse. Click somewhere in the black area to the left of cell content and use arrow keys.
script dump
jupyter nbconvert --to script --stdout foo.ipynb
Related
- https://nbconvert.readthedocs.io/en/latest/customizing.html
- https://nbconvert.readthedocs.io/en/latest/config_options.html
to install jupyter notebook
jupyter notebook comes with the jupyter package. To install it
python3 -m pip install --upgrade pip python3 -m pip install jupyter
Ref:- https://jupyter.org/install
launch jupyter notebook in chrome
machine | windows 10
- launch git bash
- Activate an environment that contains jupyter notebook
source activate <env>
- generate config
jupyter notebook --generate-config
- In ~/.jupyter/jupyter_notebook_config.py, change
#c.NotebookApp.browser = ''
to
c.NotebookApp.browser = 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s'
Ref:- https://stackoverflow.com/questions/46829761/how-to-open-jupyter-notebook-in-chrome-on-windows
launch jupyter notebook in the background
machine | windows 10
My script: https://github.com/KamarajuKusumanchi/rutils/blob/master/bin/jn.daemon
Usage:
jn.daemon [start|stop|status] <root_dir> root_dir is optional. It is set to current directory by default.
underlying commands:
- To start the server
jupyter notebook > /dev/null 2>&1 &
- To stop the servers
ps -W | grep "jupyter-notebook" | awk "{print \$1}" | xargs kill -f
See also: https://stackoverflow.com/questions/38118217/how-can-i-run-jupyter-notebook-in-background-on-windows
nbviewer not showing the latest version
This is an nbviewer FAQ. Basically it takes about 10 minutes to update, but if you want to force it, you can add ?flush_cache=true to the nbviewer URL.
open ipynb files with double click
- Install
$ cat env_test_nbopen.yml name: test_nbopen channels: - defaults dependencies: - python=3.8 - pywin32 - pip - pip: - nbopen
$ conda env create -f env_test_nbopen.yml
- Add the following at the beginning of PATH
%PY38%;%PY38%\scripts;%PY38%\library\bin;%PY38%\library\usr\bin;
where PY38 is your python environment. Ex:- C:\ProgramData\Continuum\Anaconda\envs\test_nbopen .
- Integrate with the file manager
python3 -m nbopen.install_win
Ref:-
- https://github.com/takluyver/nbopen - source code. Contains instructions on how to {install via pip, integrate with the file manager on Linux} etc.,
- https://github.com/KamarajuKusumanchi/rutils/blob/master/python3/envs/env_test_nbopen.yml - latest version of my conda environment file.
- https://github.com/takluyver/nbopen/issues/69#issuecomment-645498792 - to understand why we need to add the paths manually.