前置條件:(本例中爲Cent OS7)安裝好 jupyter notebook;例如安裝在 /home/me 目錄下、端口設置爲8888
操作目錄:jupyter_notebook_config.py 所在目錄
問題類型一、服務器端 運行 jupyter notebook 報錯
1. 提示Running as root is not recommeded. 如下圖:
[C 10:20:53.426 NotebookApp] Running as root is not recommended. Use --allow-root to bypass.
原因:一般是因爲 jupyter 安裝在非 root用戶的目錄下,故默認不支持Cent OS 用戶直接運行。此時實際上 jupyter notebook 服務並未啓動,故使用不了。
解決方法:按提示加入命令參數即可(或切換到 非 root 用戶,也可以)
jupyter notebook --allow-root
[C 10:17:49.786 NotebookApp] Bad config encountered during initialization:
[C 10:17:49.786 NotebookApp] No such notebook dir: u'/home/caihao/ipython'
最後是這兩行,上面還有一大串
原因:檢查配置文件,發現 c.NotebookApp.notebook_dir = u'/home/me/ipython',該目錄在 Cent OS 中不存在。
解決方法:手動創建目錄即可
問題類型二、無法訪問(假設地址爲:192.168.20.2)
1. 瀏覽器輸入 192.168.20.2:8888,報超時錯誤 ERR_TIME_OUT,客戶端訪問時,服務器端無提示輸出
原因:防火牆攔截 。
解決方法:關閉防火牆,或設置開放指定端口(推薦)。
①關閉防火牆
[root@centos .jupyter]# systemctl stop firewalld.service
②設置開放指定端口,重啓防火牆
[root@server240 .jupyter]# firewall-cmd --zone=public --add-port=8888/tcp --permanent
success
[root@server240 .jupyter]# systemctl restart firewalld.service
[W 10:59:32.921 NotebookApp] SSL Error on 20 ('172.31.159.149', 60102): [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:579)
原因:我的jupyter配置了 ssl 加密,客戶端瀏覽器訪問時默認是 http://xxxxx,故拒絕訪問。
解決方法:瀏覽器地址 加上 "https:" 即可
3. 瀏覽器輸入 192.168.20.2:8888 ,成功進入登錄界面,但輸入密碼後,報 404 Not Found錯誤,頁面空白。
原因:登錄成功說明 jupyter notebook 服務正常啓動了,404 找不到頁面是因爲 工作目錄有問題。覈查後,發現配置文件 jupyter_notebook_conifg.py 中缺少對工作目錄的設置
解決方法:在 jupyter_notebook_config.py 中配置 工作目錄 ,即加入如下一行:
c.NotebookApp.notebook_dir = u'/home/me/ipython'
此時配置文件的完整內容如下:c.NotebookApp.ip='*'
c.NotebookApp.password = u'sha1:ce1b91965355:c5acf3d59b844c67d0e9a6b038eda7e1ad830ee1'
c.NotebookApp.open_browser = False
c.NotebookApp.port = 8888
c.NotebookApp.certfile = u'/home/me/.jupyter/mycert.pem'
c.NotebookApp.notebook_dir = u'/home/me/ipython'
不定期更新,歡迎有新問題共同討論