python3 -m pip install --upgrade pip
python3 -m pip install jupyter
运行:
jupyter notebook
如果jupyter是运行在virtualbox虚拟机里面,那么可以设置virtualbox允许主机访问:
由于virtualbox设置成了NAT网络连接,因此需要通过端口转发的方式,允许宿主机器访问。
jupyter server的默认端口是8888,可以在virtualbox上设置端口转发如下:
设置完以后最好重启一下virtualbox,保证生效。这样在宿主机可以通过http://127.0.0.1:9090 访问
另外,jupyter可以按如下方式配置:
如果还没有配置文件,可以通过jupyter notebook --generate-config 生成.jupyter目录,里面会生成jupyter_notebook_config.py,
可以定制自己需要的配置,例如:
# Local IP addresses (such as 127.0.0.1 and ::1) are allowed as local, along
# with hostnames configured in local_hostnames.
c.NotebookApp.allow_remote_access = True
## The IP address the notebook server will listen on.
(0.0.0.0即监听所有网卡IP)
c.NotebookApp.ip = '0.0.0.0'
## The directory to use for notebooks and kernels.(设置工作目录)
c.NotebookApp.notebook_dir = '/home/xxx/jupyter'
## Whether to open in a browser after starting. The specific browser used is
# platform dependent and determined by the python standard library `webbrowser`
# module, unless it is overridden using the --browser (NotebookApp.browser)
# configuration option.
c.NotebookApp.open_browser = False
## Token used for authenticating first-time connections to the server.
#
# When no password is enabled, the default is to generate a new, random token.
#
# Setting to an empty string disables authentication altogether, which is NOT
# RECOMMENDED.
#c.NotebookApp.token = '<generated>'
c.NotebookApp.token = ''
常用快捷键:
Command Mode
-
shift+enterrun cell, select below -
ctrl+enterrun cell -
option+enterrun cell, insert below -
Ainsert cell above -
Binsert cell below -
Ccopy cell -
Vpaste cell -
D,Ddelete selected cell -
shift+Mmerge selected cells, or current cell with cell below if only one cell selected -
I,Iinterrupt kernel -
0,0restart kernel (with dialog) -
Ychange cell tocodemode -
Mchange cell tomarkdownmode (good for documentation)
Edit Mode
-
cmd+clickfor multi-cursor editing -
option+scrolling clickfor column editing -
cmd+/toggle comment lines -
tabcode completion or indent -
shift+tabtooltip -
ctrl+shift+-split cell
参考:
http://jupyter.org/install.html
https://jupyter-notebook.readthedocs.io/en/latest/public_server.html#notebook-public-server
http://maxmelnick.com/2016/04/19/python-beginner-tips-and-tricks.html