如何以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)文章!
- pip install jupyterlab失敗的原因問題及探索
- Pycharm關(guān)于遠程JupyterLab以及JupyterHub登錄問題
- JupyterLab遠程密碼訪問實現(xiàn)
- python數(shù)據(jù)可視化JupyterLab實用擴展程序Mito
- 手把手教你配置JupyterLab 環(huán)境的實現(xiàn)
- Windows 下更改 jupyterlab 默認啟動位置的教程詳解
- 解決jupyterLab打開后出現(xiàn)Config option `template_path`not recognized by `ExporterCollapsibleHeadings`問題
相關(guān)文章
python 爬取古詩文存入mysql數(shù)據(jù)庫的方法
這篇文章主要介紹了python 爬取古詩文存入mysql數(shù)據(jù)庫的方法,本文通過實例代碼給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2020-01-01利用python繪制數(shù)據(jù)曲線圖的實現(xiàn)
這篇文章主要介紹了利用python繪制數(shù)據(jù)曲線圖的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-04-04解決安裝python庫時windows error5 報錯的問題
今天小編就為大家分享一篇解決安裝python庫時windows error5 報錯的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-10-10Keras自動下載的數(shù)據(jù)集/模型存放位置介紹
這篇文章主要介紹了Keras自動下載的數(shù)據(jù)集/模型存放位置介紹,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-06-06python神經(jīng)網(wǎng)絡(luò)之批量學(xué)習(xí)tf.train.batch函數(shù)示例
這篇文章主要為大家介紹了python神經(jīng)網(wǎng)絡(luò)之批量學(xué)習(xí)tf.train.batch函數(shù)示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-05-05python“靜態(tài)”變量、實例變量與本地變量的聲明示例
這篇文章主要給大家介紹了關(guān)于python“靜態(tài)”變量、實例變量與本地變量的聲明的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-11-11解讀keras中的正則化(regularization)問題
這篇文章主要介紹了解讀keras中的正則化(regularization)問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-12-12PyCharm打代碼時出現(xiàn)白色光標(biāo)問題(筆記本的解決方案)
PyCharm中白色光標(biāo)通常是虛擬空格功能導(dǎo)致的,可以通過按下Insert鍵或在設(shè)置中取消勾選“Show virtual space at line end”選項來解決2025-02-02