Jupyter Notebook的配置(密碼端口+遠程登陸+nbextension)


1 生成配置文件

linux和mac系統打開終端
windows系統打開anaconda自帶的終端

jupyter notebook --generate-config

此時系統會生成 ~/.jupyter/ 這個隱藏文件夾,且文件夾中生成了一個jupyter的配置文件jupyter_notebook_config.py

2 配置密碼+端口+遠程登陸+工作目錄+啟動mathjax

2.1 生成jupyter的密碼

打開IDE或者命令行,輸入如下命令

from notebook.auth import passwd
passwd()
# 此時需要輸入兩次密碼(一次設置,一次確認),然后生成sha1的密文,拷貝下來。
# Enter password: ········
# Verify password: ········
# sha1:b11ba7ae862e:6eeb922ef6b770e43a1c90922ba341faaaaaaaa

輸入passwd()后需要兩次鍵入密碼,之后會產生一段密文

2.2 修改配置文件jupyter_notebook_config.py

打開jupyter_notebook_config.py,滾動到文件最后一行,加入下面的配置選項

# 允許所有ip訪問
c.NotebookApp.ip='*' 

# 密碼 2.1中生成'sha1:xxxx"那一大串,復制時包括sha1 
c.NotebookApp.password = 'sha1:0d00e0994444:3aeecafab4d91260d42647df8df4c3859a3430a9' 

# 是否打開瀏覽器 
c.NotebookApp.open_browser = False 

# 指定端口 jupyter的默認端口為8888
c.NotebookApp.port = 10000

# 啟用 MathJax 
c.NotebookApp.enable_mathjax = True 

# 修改工作空間文件夾  '/home/jupyter/'改成你的目錄
c.NotebookApp.notebook_dir = '/home/jupyter/'

2.3 啟動jupyter notebook

在服務器上使用jupyter notebook啟動

nohup jupyter notebook --no-browser --allow-root --ip=0.0.0.0 --port=8080 --notebook-dir=/ &

然后本機通過http://address_of_remote:10000遠程訪問即可,登錄界面需要輸入設置的密碼。

3 Jupyter安裝nbextensions

如果你已經安裝了,先執行卸載命令:

pip uninstall jupyter_contrib_nbextensions
pip uninstall jupyter_nbextensions_configurator

打開Anaconda Prompt窗口,執行第一個命令,用於安裝nbextensions:

pip install jupyter_contrib_nbextensions

再執行第二個命令,用於安裝 javascript and css files

jupyter contrib nbextension install --user

最后執行,用於安裝configurator

pip install jupyter_nbextensions_configurator

然后重新啟動Jupyter Notebook后,就會發現已經有Nbextensions標簽了。

常用擴展功能,勾選上即可:
最常用功能說明,建議勾選上:

  • Collapsible headings 折疊標題
  • Notify 通知機制,跑一些耗時較久的任務,完成后通知
  • Codefolding 折疊代碼
  • Zen mode extension 隱藏活動狀態欄,方便注意代碼
  • Execute time extension 顯示運行的時間


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM