本文檔介紹瞭如何通過本地的瀏覽器訪問啓動在遠程服務器上的jupyter notebook。
首先,確定服務器上安裝了jupyter notebook,沒有安裝可以通過pip安裝,命令如下:
pip install jupyter notebook
然後,檢查是否已經產經notebook配置文件:jupyter_notebook_config.py,該配置文件默認的路徑如下:
WINDOWS: C:\User\USERNAME.jupyter\jupyter_notebook_config.py
OS X: /User/USERNAME/.jupyter/jupyter_notebook_config.py
lINUX: /home/USERNAME/.jupyter/jupyter_notebook_config.py
如果沒有該文件,通過下面命令創建:
jupyter notebook --generate-config
下面介紹兩種方式爲jupyter notebook創建登錄密碼
方法一:先創建一個密碼,該密碼用來在本地登錄遠程服務器上的jupyter notebook,在服務器上打開Python環境,輸入下面代碼:
from notebook.auth import passwd
passwd()
Enter password: # 輸入密碼,此密碼用來遠程登錄jupyter notebook
Verify password: # 再次驗證密碼,回車,會生成下面密文
'sha1:7***********************87d21'
打開剛纔創建的upyter_notebook_config.py文件,設置訪問notebook的ip:
c.NotebookApp.ip='*' # *表示所有IP,這裏設置ip爲都可訪問
c.NotebookApp.password = 填寫剛剛生成的密文
c.NotebookApp.open_browser = False # 禁止notebook啓動時自動打開瀏覽器(在linux服務器一般都是ssh命令行訪問,沒有圖形界面的。所以,啓動也沒啥用)
c.NotebookApp.port =9000 # 指定訪問的端口,默認是8888
啓動jupyter notebook,在本地瀏覽器上面訪問:9000,(上面指定端口爲9000)出現notebook登錄頁面,輸入密碼即可使用。
方法二: 直接在服務器命令行輸入下面命令,此操作會在和jupyter_notebook_config.py相同目錄下創建jupyter_notebook_config.conf文件,裏面保存着輸入密碼的密文,同樣可以用來登錄jupyter notebook
jupyter notebook password
Enter password: ****
Verify passsword: ****
[NotebookPasswordApp] Wrote hashed password to /Users/you/.jupyter/jupyter_notebook_config.json
有關於jupyter notebook的更多配置,請參考官方文檔,<官方文檔傳送門>