- 安装jupyter, ipython
- 远程访问
安装jupyter, ipyhton
>>> sudo python3 -m pip install ipython==6.5.0
>>> sudo python3 -m pip install jupyter
最新的ipython==7.2.0和jupyter的prompt-tookit版本冲突,因而安装ipython==6.5.0。
最后jupyter安装在了~/.local/bin/路径下。
>>> jupyter notebook
jupyter: command not found
需要在.bashrc中设置环境变量
>>> vim ~/.bashrc
在文件最后加上
export PATH=$PATH:~/.local/bin
>>> source .bashrc
远程访问
jupyter notebook默认只能通过本机的localhost访问服务器,我们可以通过修改配置实现远程访问。
- 生成配置文件
>>> jupyter notebook --generate-config
如果提示权限不够可先修改权限
>>> sudo chmod 777 .jupyter/
>>> jupyter notebook --generate-config
- 修改配置文件
>>> vim .jupyter/jupyter_notebook_config.py
修改其中两个参数
c.NotebookApp.allow_origin = '*' #允许从任何来源访问服务器
c.NotebookApp.ip = '0.0.0.0' #监听所有IP地址
>>> jupyter notebook --no-browser
记下生成的token
在Mac上打开浏览器,输入http://xx.xx.xx.xx:8888
输入生成的token即可。
2019年3月11日更新:
添加设置密码,避免输入token
打开ipython
>>> from notebook.auth import passwd
>>> passwd()
Enter password: (password)
Verify password: (password)
'sha1:xxxxxxxxxxxxxxxxxxxxxxx'
复制哈希值,粘贴到’.jupyter/jupyter_notebook_config.py’中的’c.NotebookApp.password='处,并取消注释,保存退出