1、运行jupyterlab
python环境使用miniconda;
当在python中安装好jupyterlab后(假设安装在miniconda的base中),在miniconda目录下创建jupyterlab_run.bat用于运行jupyterlab:
jupyter lab --config jupyter_notebook_config.py # 启动jupyterlab,--config 后是配置文件(jupyter lab --genetate-config 生成)
创建jupyterlab_activate_run.bat 用于激活conda环境后,运行jupyterlab:
@echo off
set CONDA=%~dp0\condabin\conda.bat #设置conda
call %~dp0\Scripts\activate.bat %~dp0 #激活当前环境
call jupyterlab_run.bat #通过调用之前创建的批处理来运行 jupyterlab
完成后可直接双击运行 jupyterlab_activate_run.bat运行测试;
2、安装服务(nssm)
win服务使用 nssm 工具;nssm具体的使用可参考官网;
将nssm.exe放至miniconda目录下,以管理员运行cmd并进入至此目录后:
nssm install test_jupyterlab #安装服务
nssm edit test_jupyterlab #编缉此服务
在弹出框中,Application切页,
Startup directory:填入minoconda的目录;
Path:填入步骤1创建的jupyterlab_activate_run.bat
IO 切页中可设置输出日志。
即将此bat运行文件安装成服务,完成后启动服务即可。
在web浏览器中输入相应的地址即可访问已启动的jupyterlab;
3、遇到的故障
但在服务状态下,出现了一个故障,而若在cmd命令框下是正常的:
在选择kernel时会提示报错:
pywintypes.error: (1332, 'LookupAccountName', '帐户名与安全标识间无任何映射完成。')
这个错误应该是和服务运行的账户权限有关,通过以下方法来解决。
找到miniconda环境下的 lib/site-packages/jupyter_core,打开path.py,搜索 win32security.LookupAccountName:
user, _domain, _type = win32security.LookupAccountName("", win32api.GetUserNameEx(win32api.NameSamCompatible))
将其注释,替换为:
user, _domain, _type = win32security.LookupAccountName("", win32api.GetUserName())
重启服务后故障消失。不知是什么原因,但目前只能先这样处理。
参考资料:
https://juejin.im/post/595897c36fb9a06bca0b91eb
https://github.com/jupyter/jupyter_client/pull/478