1.开启外网访问
1.1 生成notebook配置文件
linux默认情况下,配置文件~/.jupyter/jupyter_notebook_config.py文件并不存在,需要自行创建:
jupyter notebook --generate-config
windows下该命令同样会生成配置文件,默认路径在C:\Users\Administrator.jupyter\
1.2 生成密码
jupyter 5.0版本以上,使用命令:
jupyter notebook password
生成密码并存储在jupyter_notebook_config.json
1.3 修改配置文件
在jupyter_notebook_config.py找到下面的配置,并修改:
c.NotebookApp.ip='*' #在所有的网卡接口上开启服务
c.NotebookApp.port =8888 #可自行指定一个端口, 访问时使用该端口7777
c.NotebookApp.allow_remote_access = True #允许远程
注:如果使用阿里云或腾讯云服务器,需要将对应端口添加至安全组里;windows服务器,要将端口添加到防火墙中。
1.4 修改默认工作路径
可以在jupyter_notebook_config.py文件中查找c.NotebookApp.notebook_dir并修改:
c.NotebookApp.notebook_dir = 'D:\\xx\xx'
2.定时运行
2.1 编写脚本文件
jupyter定时执行,使用crontab的定时任务执行编写好的脚本文件,新建脚本文件jupyter.sh:
@echo off & setlocal
set "target=C:\Users\Administrator\Desktop\ipynb"
for %%i in ("%target%\*.ipynb") do (
jupyter nbconvert --execute --to script %%i
)
endlocal & @echo on
2.2 添加定时任务
*/1 * * * * sh /home/jupyter.sh