文章目录
普通部署
1. 安装jupyter notebook
pip install jupyter -i https://mirrors.aliyun.com/pypi/simple/
2. 生成配置文件
jupyter notebook --generate-config --allow-root
会生成配置文件 ~/.jupyter/jupyter_notebook_config.py
3. 生成密码
jupyter notebook password
输入两次密码,会生成密码文件 ~/.jupyter/jupyter_notebook_config.json
4. 修改配置文件
在配置文件添加如下配置
c.NotebookApp.ip = '*'
c.NotebookApp.allow_root = True
c.NotebookApp.open_browser = False
c.NotebookApp.port = 8888
c.NotebookApp.password = u'刚才生成的密文'
c.ContentsManager.root_dir = '工作目录'
5. 运行jupyter
使用nohup &命令或者借助screen实现jupyter的后端运行
jupyter notebook
仍然访问不了有可能是购买的云服务器有防火墙,需要到云服务器网站上设置安全访问规则
6. 主题设置
docker部署
1. docker安装与配置
2. 下载jupyter镜像
查找镜像
docker search jupyter
如果没特别需要可以下载基础版本镜像jupyter/base-notebook,后续根据需要再安装其他包
docker pull jupyter/base-notebook
3. 新建工作目录
把容器内的工作目录映射到宿主机的目录上,方便对工作目录管理
mkdir ~/jupyter_ws
改目录权限,jupyter容器要在该目录新建目录或文件,需要足够的权限
chmod 777 jupyter_ws
4. 启动容器
docker run -d -p 8888:8888 -v ~/jupyter_ws:/home/jovyan/work jupyter/base-notebook
5. 设置密码
- 首次使用ip:8888访问jupyter会提示输入token登录或者创建密码
- token可以通过
docker logs <jupyter容器id/名称>
查看,复制token - 在jupyter页面粘贴token输入要创建的密码
6. 更改主题
- 登录jupyter,新建terminal,安装主题
pip install jupyterthemes -i https://mirrors.aliyun.com/pypi/simple
- 设置新主题
jt -t grade3 -f fira -fs 14 -cellw 90% -ofs 15 -dfs 15 -T -T
更多主题设置可以查看Jupyter Notebook 更换主题(背景、字体)