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 + enter run cell, select below
  • ctrl + enter run cell
  • option + enter run cell, insert below
  • A insert cell above
  • B insert cell below
  • C copy cell
  • V paste cell
  • D , D delete selected cell
  • shift + M merge selected cells, or current cell with cell below if only one cell selected
  • I , I interrupt kernel
  • 0 , 0 restart kernel (with dialog)
  • Y change cell to code mode
  • M change cell to markdown mode (good for documentation)

Edit Mode

  • cmd + click for multi-cursor editing
  • option + scrolling click for column editing
  • cmd + / toggle comment lines
  • tab code completion or indent
  • shift + tab tooltip
  • 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

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐