在服务器上配置部署jupyter notebook 服务
我们可以将jupyter notebook的服务部署在服务器上,之后我们就可以通过域名或者ip来使用jupyter notebook服务。
实验环境:
ubuntu16.04
python 3.6.7
下面我们通过以下步骤来安装一个在服务器端运行的jupyter notebook服务,主要步骤如下:
- 在服务器上创建一个文件夹,并创建好虚拟环境
mkdir ~/my_jupyter cd ~/myjupyter python -m venv venv # 创建虚拟环境 source venv/bin/activate
- 在当前虚拟环境下安装jupyter
pip install jupyter
- 生成jupyter配置文件
运行完上述命令后,会生成jupyter notebook --generate-config
~/.jupyter/jupyter_notebook_config.py
的配置文件。 - 生成jupyter notebook 的登录密钥,打开python交互式解释器,然后输入以下代码来设置密码
from notebook.auth import passwd passwd() # 接下来输入密码即可
- 修改配置文件:在文件的末尾加上以下代码:
c.NotebookApp.ip='*' # 设置任何IP都可以访问 c.NotebookApp.password = u'设置密码后产生的密文' c.NotebookApp.open_browser = False # 禁止自动打开浏览器 c.NotebookApp.port =8888 # jupyter notebook的启动端口 c.NotebookApp.allow_remote_access = True # 允许远程连接
- 启动jupyter notebook服务,并将其运行在后台
sudo nohup jupyter notebook&
- 在浏览器中输入
http://服务器IP:8888
即可访问到jupyter notebook服务。
添加jupyter notebook扩展
- 安装扩展所需要的第三方库
pip install jupyter_contrib_nbextensions
- 将扩展安装到jupyter
jupyter contrib nbextension install --user
- 重启jupyter notebook服务
nohup jupyter notebook&
在jupyter notebook中执行shell命令
使用!
前缀可以让jupyter notebook执行shell命令
- 安装python第三方包
!pip install requests
- 执行基本shell命令
ls