一. Ubuntu下安裝jupyter notebook
1. 使用Anaconda安裝
conda install jupyter notebook
2. 使用pip安裝
pip install jupyter notebook
二. Jupyter notebook 配置
1. 生成配置文件
jupyter notebook --generate-config
2. 創(chuàng)建密碼
使用python中的passwd()
創(chuàng)建密碼,終端輸入ipython
打開(kāi)ipython并輸入:
In [1]: from notebook.auth import passwd
In [2]: passwd()
Enter password: ******
Verify password: ******
Out [2]: 'sha1:...'
復(fù)制Out [2] 顯示的密碼('sha1:...' 包括引號(hào))筑煮。
3. 修改jupyter notebook的配置文件
- 打開(kāi)配置文件
vim ~/.jupyter/jupyter_notebook_config.py
- 在該文件中做如下修改或直接在文件尾端添加:
c.NotebookApp.allow_remote_access = True #允許遠(yuǎn)程連接
c.NotebookApp.ip='*' # 設(shè)置所有ip皆可訪問(wèn)
c.NotebookApp.password = u'sha:..' #之前復(fù)制的密碼
c.NotebookApp.open_browser = False # 禁止自動(dòng)打開(kāi)瀏覽器
c.NotebookApp.port =8888 #任意指定一個(gè)端口
4. 啟動(dòng)jupyter notebook
終端輸入:
jupyter notebook
或使用nohup
后臺(tái)運(yùn)行 jupyter notebook:
nohup jupyter notebook >~/jupyter.log 2>&1&
5. 遠(yuǎn)程訪問(wèn)jupyter notebook
本地瀏覽器輸入http://(服務(wù)器地址):(配置文件中設(shè)定的端口)
;
假設(shè)服務(wù)器地址為192.168.1.129色罚,配置的端口為8888,這里的瀏覽器輸入地址應(yīng)為http://192.168.1.129:8888
账劲;
即可訪問(wèn)jupyter notebook戳护。
更新 (2020/11/26)
- 使用使用python中的
passwd()
創(chuàng)建密碼時(shí),新的格式會(huì)和之前不同瀑焦。
'argon2:$argon2id...'
可以直接將上述字符串復(fù)制到c.NotebookApp.password
中腌且,最終結(jié)果如圖所示
c.NotebookApp.password ='argon2:$argon2id...' #之前復(fù)制的密碼
- 如果希望jupyter notebook中使用conda虛擬環(huán)境的配置,需要在相應(yīng)的虛擬環(huán)境中進(jìn)行以下操作為conda環(huán)境安裝ipykernel 內(nèi)核:
python -m ipykernel install --user --name myenv --display-name "Python (myenv)"
移除ipykernel命令:
jupyter kernelspec uninstall unwanted-kernel
unwanted-kernel 替換為自己的虛擬環(huán)境名稱榛瓮。