亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

如何以Winsows Service方式運行JupyterLab

 更新時間:2020年08月30日 15:31:15   作者:Ken.W  
這篇文章主要介紹了如何以Winsows Service方式運行JupyterLab的教程

有數(shù)據(jù)分析,數(shù)據(jù)挖掘,以及機器學(xué)習(xí)和深度學(xué)習(xí)實踐經(jīng)驗的讀者應(yīng)該會對Jupyter Notebook這一工具十分熟悉,而JupyterLab是它的升級版本,其提供了更具擴展性,更加可定制化的功能選項。

安裝與啟動JupyterLab的方法與Jupyter Notebook一樣簡單。

應(yīng)用安裝

pip install jupyterlab

應(yīng)用啟動

jupyter lab

但這樣的操作會帶來一個問題,在以瀏覽器打開JupterLab應(yīng)用窗口的同時,必須始終保證命令行窗口同樣處于打開狀態(tài)。如下圖所示:

要想解決這樣的問題,需要將JupyterLab以Windows Service的方式運行。

而Python代碼要在Windows系統(tǒng)里創(chuàng)建Service的話要用到win32serviceutil這個類庫。

類庫安裝

pip install pywin32

服務(wù)代碼

將以下代碼保存為jupyterlabservice.py文件,并放在配置目錄之下,如C:\Users\Ken\.jupyter

import inspect
import logging
import os
import win32serviceutil
from jupyterlab.labapp import JupyterApp, LabApp

current_file = os.path.abspath(inspect.getfile(inspect.currentframe()))
os.chdir(os.path.dirname(current_file))


class JupyterLabService(win32serviceutil.ServiceFramework):

  _svc_name_ = "JupyterLab"
  _svc_display_name_ = "Jupyter Lab Service"
  _svc_description_ = "Jupyter Lab Service"

  def __init__(self, args):
    super().__init__(args)
    self.app = LabApp()

  def _init_lab(self):
    JupyterApp.initialize(self.app)
    self.app.init_configurables()
    self.app.init_components()
    self.app.init_webapp()
    self.app.init_terminals()
    self.app.init_server_extensions()
    self.app.init_mime_overrides()
    self.app.init_shutdown_no_activity()

  def SvcDoRun(self):
    self.app.config_dir = "."
    self._init_lab()
    self.app.start()

  def SvcStop(self):
    self.app.stop()

  def SvcShutdown(self):
    self.SvcStop()


if __name__ == '__main__':
  win32serviceutil.HandleCommandLine(JupyterLabService)

服務(wù)安裝

python .\jupyterlabservice.py install

服務(wù)啟動

python .\jupyterlabservice.py start

訪問localhost:8888網(wǎng)址,可以在瀏覽器中打開JupyterLab應(yīng)用,但此時會遇到需要token認證的問題,如下圖所示:

解決此問題方法是修改配置文件中的token參數(shù)。

首先是在配置目錄中找到jupyter_notebook_config.py文件,如果沒有的話可以通過以下命令創(chuàng)建。

jupyter lab --generate-config

然后找到c.NotebookApp.token一項,將其值設(shè)為空字符串。

## Token used for authenticating first-time connections to the server.
#
# The token can be read from the file referenced by JUPYTER_TOKEN_FILE or set
# directly with the JUPYTER_TOKEN environment variable.
#
# When no password is enabled, the default is to generate a new, random token.
#
# Setting to an empty string disables authentication altogether, which is NOT
# RECOMMENDED.
c.NotebookApp.token = ''

重啟相應(yīng)服務(wù)后,再次訪問localhost:8888網(wǎng)址,這下就正常了。

如果不想使用默認的8888端口,也可以在c.NotebookApp.port選項中將其值改成特定的端口號。

## The port the notebook server will listen on (env: JUPYTER_PORT).
c.NotebookApp.port = 9999

再次重啟服務(wù),這次便可以通過localhost:9999來訪問JuypterLab應(yīng)用了。

作者:Ken.W
出處:http://www.cnblogs.com/kenwoo

以上就是如何以Winsows Service方式運行JupyterLab的詳細內(nèi)容,更多關(guān)于運行JupyterLab的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評論