生成設定檔
裝好Anaconda後,執行Anaconda Prompt輸入以下指令
- $ jupyter notebook –generate-config
就會產生檔案「jupyter_notebook_config.py」在以下位置:
- C:Users[使用者名稱].jupyterjupyter_notebook_config.py
jupyter_notebook_config.py內常用的程式碼片段
- 設定SSL/TLS憑證檔路徑(最後會說明怎麼自己產生憑證和私鑰):
- ## The full path to an SSL/TLS certificate file.
例如:
c.NotebookApp.certfile = r”C:keymycert.pem”
- ## The full path to an SSL/TLS certificate file.
- 設定可連線的IP範圍,’*’ 表不限:
- ## The IP address the notebook server will listen on.
例如:
c.NotebookApp.ip = ‘*’
- ## The IP address the notebook server will listen on.
- 設定SSL/TLS私鑰檔(私密金鑰)路徑:
- ## The full path to a private key file for usage with SSL/TLS.
例如:
c.NotebookApp.keyfile = r”C:keymykey.key”
- ## The full path to a private key file for usage with SSL/TLS.
- 首次登入要更改密碼:(如果等下用hash code就不用改這個設定)
## Allow password to be changed at login for the notebook server. # # While loggin in with a token, the notebook server UI will give the opportunity # to the user to enter a new password at the same time that will replace the # token login mechanism. # # This can be set to false to prevent changing password from the UI/API. c.NotebookApp.allow_password_change = True
- 設定剛執行jupyter的是否要自動開瀏覽器:
- c.NotebookApp.open_browser = True
- 填入自訂密碼的hash值:
- ## Hashed password to use for web authentication.
c.NotebookApp.password = ”用python語法產生: - from notebook.auth import passwd
passwd()
- ## Hashed password to use for web authentication.
- Port設定
- ## The port the notebook server will listen on. c.NotebookApp.port = 8888
- 執行後的視窗開啟方式
- # 2 opens a new tab,
# 1 opens a new window,
# 0 opens in an existing window.
c.NotebookApp.webbrowser_open_new = 2
- # 2 opens a new tab,
- 可復原編輯字數上限
- ## The maximum number of digests to remember.
c.Session.digest_history_size = 65536
- ## The maximum number of digests to remember.
憑證與私鑰
上述程式碼片段1.和3.所需的檔案,必須先安裝openssl library,可是官網我找不到for windows的安裝檔,原先參考stackoverflow: unable to load config info from /usr/local/ssl/openssl.cnf),跑去安裝git for windows才知道安裝的時候會選擇安裝openssl library(但我後來發現xamppapacheconfopenssl.cnf就已經有了,所以以下路徑可以改成這個),路徑在:
- [Git目錄]usrsslopenssl.cnf 或者
- [apache目錄]confopenssl.cnf
接著設定路徑
- $ set OPENSSL_CONF=[Git目錄]usrsslopenssl.cnf
然後用openssl指令產生self-signed certificate file:
- $ openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout mykey.key -out mycert.pem
它會問你一堆問題後生成兩個檔案(mykey.key和mycert.pem),將它們放在一個你不會亂刪的資料夾內,再去前述1.和3.的路徑設定加上就完成了。
後續其他問題
- Windows 10執行時必須「以系統管理員身分執行」,否則會出現Kernel error。
- C:Users[使用者名]AppDataRoamingMicrosoftWindowsStart MenuProgramsAnaconda3 (64-bit)中的Jupyter Notebook (Anaconda3)捷徑,按右鍵看內容,要修改下列參數:
- 目標(T)之中
- jupyter-notebook-script.py後方的參數拿掉
- 開始位置欄位清空
- 這個步驟做了才可以自訂開啟時的home位置,參數如下:
- ## The directory to use for notebooks and kernels.
c.NotebookApp.notebook_dir = “[自訂完整路徑]”
- ## The directory to use for notebooks and kernels.
- 目標(T)之中