原文地址: https://blog.csdn.net/simple_the_best/article/details/77005400
首先是要 安裝 Anaconda 甲捏。
默認情況下钦睡,安裝好 Anaconda 后打開 jupyter notebook, 訪問本地
localhost:8888 即可。但是如果要訪問另一臺機器服鹅,比如遠端服務(wù)器上的 notebook, 即默認是不支持 172.104.105.119:8888 這樣的訪問愤兵,需要額外配置。
設(shè)置 jupyter notebook 可遠程訪問的官方指南在這里,在遠端服務(wù)器上執(zhí)行以下操作:
1. 生成一個 notebook 配置文件
默認情況下几苍,配置文件 ~/.jupyter/jupyter_notebook_config.py 并不存在,需要自行創(chuàng)建陈哑。使用下列命令生成配置文件:
jupyter notebook --generate-config
如果報錯ModuleNotFoundError: No module named 'importlib_metadata'
妻坝,那就升級一下notebook
pip install notebook --upgrade
如果是 root 用戶執(zhí)行上面的命令,會發(fā)生一個問題:
Running as root it not recommended. Use --allow-root to bypass.
提示信息很明顯惊窖,root 用戶執(zhí)行時需要加上 --allow-root 選項刽宪。
jupyter notebook --generate-config --allow-root
執(zhí)行成功后,會出現(xiàn)下面的信息:
Writing default config to: /root/.jupyter/jupyter_notebook_config.py
2. 生成密碼
自動生成
從 jupyter notebook 5.0 版本開始界酒,提供了一個命令來設(shè)置密碼:jupyter notebook password圣拄,生成的密碼存儲在 jupyter_notebook_config.json。
$ jupyter notebook password
Enter password: ****
Verify password: ****
[NotebookPasswordApp] Wrote hashed password to /Users/you/.jupyter/jupyter_notebook_config.json
手動生成
除了使用提供的命令毁欣,也可以通過手動安裝庇谆,我是使用的手動安裝,因為jupyter notebook password 出來一堆內(nèi)容署辉,沒耐心看族铆。打開 ipython 執(zhí)行下面內(nèi)容:
In [1]: from notebook.auth import passwd
In [2]: passwd()
Enter password:
Verify password:
Out[2]: 'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'
sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed
這一串就是要在 jupyter_notebook_config.py 添加的密碼。
c.NotebookApp.password = u'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'
3. 修改配置文件
在 jupyter_notebook_config.py 中找到下面的行哭尝,取消注釋并修改哥攘。
c.NotebookApp.ip='*'
c.NotebookApp.password = u'sha:ce...剛才復(fù)制的那個密文'
c.NotebookApp.open_browser = False
c.NotebookApp.port =8888 #可自行指定一個端口, 訪問時使用該端口
c.NotebookApp.allow_remote_access = True # (!!!更新,最近一次嘗試這一句也得更改,以前是不用的)
以上設(shè)置完以后就可以在服務(wù)器上啟動 jupyter notebook
逝淹,jupyter notebook, root
用戶使用jupyter notebook --allow-root
耕姊。打開 IP:指定的端口, 輸入密碼就可以訪問了。
需要注意的是不能在隱藏目錄 (以 . 開頭的目錄)下啟動 jupyter notebook, 否則無法正常訪問文件栅葡。