Jupyter Notebook is an web app, part of Jupyter project
%env CUDA_VISIBLE_DEVICES 5
%matplotlib inline
%load_ext autoreload
%autoreload 2
source activate myenv
# install jupyter lab
conda install -c conda-forge jupyterlab
# set password to avoid using tokens
jupyter notebook password
# add kernel spec for env
python -m ipykernel install --user --name myenv --display-name "Python (myenv)"
# start jupyter server, use ip 0.0.0.0 to allow acesss from any local net
jupyter notebook --ip 0.0.0.0 --port=10010 --notebook-dir=/data/songhongwei/
# add these lines to jupyter notebook
%env CUDA_VISIBLE_DEVICES 2
%pylab
# shortcut to switch tabs
shitf + ctrl + "["
shitf + ctrl + "}"
Kernels wraps languages & provice calculation for frontend, e.g. ipython for python
3.1 Install Kernels
- install kernel specs for envs
source activate myenv
python -m ipykernel install --user --name myenv --display-name "Python (myenv)"
3.2 Kernel Specs
- what is kernelspec
each kernelspec is a directory installed by ipykernel, contains configuration of a kernel - list available kernelspecs
jupyter kernelspec list
- delete a kernel spec
delete the kernelspec directory
Magic commands start with %
- set up env
%env CUDA_VISIBLE_DEVICES 5
or
%set_env CUDA_VISIBLE_DEVICES 5
- matplotlib show plot, Set again if not plotting inline
%matplotlib inline
- print info an object
%pinfo \[obj\] / %pinfo2 \[obj\]
same as: obj? / obj??
- print signature of a callable
%pdef \[callable\]
- import numpy, matplotlib and activate interactive support
%pylab
- run shell command
!COMMAND #run command
!!COMMAND #run command and get output as a list
#example
audio_path = /sdfs/sdda
!ls $audio_path
- print variables
%who #pirnt interactive variables
%whos #print interactive variables, with extra infomation
- config autocomplete
%config IPCompleter.greedy=True
- autoreload automatically reload changes of the python files
%load_ext autoreload
%autoreload 2 #autoreload all modules
- see stanford examples
- display audio
import IPython.display as ipd
audio_obj = ipd.Audio(filename='/path/to/audio')
# need to call display() to show, if not returned to jupyter cell
from IPython.display import display
display(audio_obj)config without security
- 1.generate notebook config file
# will generate ~/.jupyter/jupyter_notebook_config.py
jupyter notebook --generate-config
-
- config a password to avoid input tokens
# will generate ~/.jupyter/jupyter_notebook_config.json, which save the password hash
jupyter notebook password- 3.change alowed ip to 0.0.0.0 in
jupyter_notebook_config.pyconfig file
# edit jupyter_notebook_config.py file
c.NotebookApp.ip = '0.0.0.0'
- 4.run notebook/lab on server and open browser on windows
# on linux
jupyter notebook # or `jupyter lab`
# on windows browser
192.168.11.214:8889 # for notebook
192.168.11.214:8889/lab # for lab
- jupyter lab is a server extention over jupyter notebook
# URL for jupyter notebook
http(s)://<server:port>/<lab-location>/tree
# URL for jupyter lab
http(s)://<server:port>/<lab-location>/lab
# start, specify serve port and dir
jupyter notebook --port=9991 --notebook-dir=/data/songhongwei/
# command line options
jupyter notebook --notebook-dir=/data/songhongwei/
# command line
jupyter notebook --NotebookApp.base_url=/asc
# change ~/jupyter/jupyter_notebook_config.py
# note the *under-slash* differ from command line *inter-slash*
c.NotebookApp.notebook_dir=/data/songhongwei/
# see a list of options
jupyter notebook --help
# see a full list of options
jupyter notebook --help-all
jupyter notebook list/stop
conda install -c conda-forge jupyterlab
# invoke jupyterlab
jupyter lab
shitf + ctrl + "["
shitf + ctrl + "}"