什么是Jupyter
Jupyter Notebooks 是一款開源的網(wǎng)絡(luò)應(yīng)用,我們可以將其用于創(chuàng)建和共享代碼與文檔爱咬。他提供了一個在線平臺中鼠,你可以在其中編寫你的代碼胯究、運(yùn)行代碼、查看輸出炕婶、可視化數(shù)據(jù)并查看結(jié)果姐赡。這個工具在數(shù)據(jù)科學(xué)/機(jī)器學(xué)習(xí)領(lǐng)域被廣泛應(yīng)用,但是我覺得用來作為系統(tǒng)演示柠掂、系統(tǒng)的性能監(jiān)測也是一個很不錯的工具项滑!下面我會在接下來的文章里使用jupyter對Ceph的性能進(jìn)行實(shí)時監(jiān)測以及可視化,本篇主要介紹如何安裝Jupyter涯贞,以及如何進(jìn)行相關(guān)的配置枪狂。
安裝Jupyter
在Centos等Linux系統(tǒng)中使用pip命令(python 2)很容易安裝jupyter:
pip install ipython jupyter notebook
安裝如果遇到問題,請查看最后一節(jié):問題總結(jié)宋渔。
配置遠(yuǎn)程登錄
由于我是在服務(wù)器上對Ceph進(jìn)行性能測試州疾,所以我希望能遠(yuǎn)程訪問,下面進(jìn)行遠(yuǎn)程訪問的配置皇拣,首先運(yùn)行下面的命令產(chǎn)生配置文件:
jupyter notebook --generate-config
為了比較安全的訪問服務(wù)器資源严蓖,我們需要設(shè)置登錄密碼和設(shè)置https來實(shí)現(xiàn)安全登錄。如果有條件可以通過安全認(rèn)證中心來發(fā)放秘鑰和認(rèn)證氧急。首先打開ipython颗胡,生成sha1的密碼,命令如下:
from notebook.auth import passwd
passwd()
設(shè)置好密碼之后會產(chǎn)生一個密鑰:
Enter password:
Verify password:
Out[2]: 'sha1:1b4ea9662b35:3e3d6a821d264d466f125a0939623c05e7b66007'
然后打開配置文件的路徑吩坝,進(jìn)行相應(yīng)的設(shè)置毒姨,記得取消注釋:
c.NotebookApp.password = 'sha1:<your-sha1-hash-value>'
c.NotebookApp.port = 8888
# 如果使用'*'可能會出現(xiàn)問題
c.NotebookApp.ip = '0.0.0.0'
c.NotebookApp.open_browser = False
安裝完成之后,啟動jupyter钉寝,然后在瀏覽器中輸入服務(wù)器地址以及":port"即可使用弧呐。
安裝插件管理器
安裝插件:
python -m pip install jupyter_contrib_nbextensions
jupyter contrib nbextension install --user --skip-running-check
安裝好之后闸迷,重新刷新或重啟jupyter,即可看到插件管理器的菜單Nbextension:
打開該菜單俘枫,可以看到里面各種各樣的菜單腥沽,勾選即可安裝:
這篇文章總結(jié)了那些比較實(shí)用的插件:https://www.jiqizhixin.com/articles/2018-12-20-12。
問題總結(jié)
安裝出現(xiàn)編碼錯誤
在安裝Jupyter之后崩哩,出現(xiàn)了下面的問題:
在python2.7環(huán)境下巡球,安裝jupyter notebook后言沐,輸入下面的命令之后邓嘹,打開jupyter失敗:
jupyter notebook
錯誤log如下:
The Jupyter HTML Notebook.
這將啟動一個基于tornado的HTML筆記本服務(wù)器险胰,它提供一個html5/
javascript筆記本客戶端汹押。
Traceback (most recent call last):
File "/anaconda2/envs/python3/bin/jupyter-notebook", line 11, in <module>
sys.exit(main())
File "/anaconda2/envs/python3/lib/python2.7/site-packages/jupyter_core/application.py", line 266, in launch_instance
return super(JupyterApp, cls).launch_instance(argv=argv, **kwargs)
File "/anaconda2/envs/python3/lib/python2.7/site-packages/traitlets/config/application.py", line 657, in launch_instance
app.initialize(argv)
File "<decorator-gen-7>", line 2, in initialize
File "/anaconda2/envs/python3/lib/python2.7/site-packages/traitlets/config/application.py", line 89, in catch_config_error
app.print_help()
File "/anaconda2/envs/python3/lib/python2.7/site-packages/traitlets/config/application.py", line 385, in print_help
self.print_subcommands()
File "/anaconda2/envs/python3/lib/python2.7/site-packages/traitlets/config/application.py", line 377, in print_subcommands
print(os.linesep.join(lines))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 4: ordinal not in range(128)
Google后參考github上的一個issue,https://github.com/jupyterlab/jupyterlab/issues/5345起便,看到有人切換語言解決問題的:
LANG=zn jupyter notebook
于是在.bashrc文件中添加:
alias jupyter='LANG=zn jupyter'
插件管理器依賴錯誤
在安裝插件管理器時同樣遇到了問題:
python -m pip install jupyter_contrib_nbextensions
jupyter contrib nbextension install --user --skip-running-check
出現(xiàn)six版本過低棚贾,于是使用pip安裝指定版本:
pip install six==1.12.0
下一篇我講介紹如何在Ceph中應(yīng)用Jupyter。
參考資料
- Jupyter notebook extensions 擴(kuò)展插件的安, https://blog.csdn.net/dyw_666666/article/details/81122095
- Jupyter打開出錯:'ascii' codec can't decode byte 0xe5 in position 4: ordinal not in range(128), http://www.reibang.com/p/516eb2a57ee6
- pip install 安裝指定版本的包, https://blog.csdn.net/youcharming/article/details/51073911
- 基于CentOS7安裝Jupyter Notebook, https://blog.csdn.net/qq_16149777/article/details/82455287
- 設(shè)置 jupyter notebook 可遠(yuǎn)程訪問, https://blog.csdn.net/simple_the_best/article/details/77005400
- jupyter throwing error: socket.gaierror: [Errno -2] Name or service not known, https://stackoverflow.com/questions/52706238/jupyter-throwing-error-socket-gaierror-errno-2-name-or-service-not-known
- jupyter使用教程, https://www.zhihu.com/question/59392251