一.介紹
Jupyther notebook(曾經的Ipython notebook),是一個可以把代碼、圖像、注釋、公式和作圖集於一處,實現可讀性及可視化分析的工具,支持多種編程語言。官方使用手冊。
安裝前,你需要裝好python環境,並且安裝pip包管理器。
二. 安裝
使用pip安裝jupyter notebook
Python2
pip install --upgrade pip
sudo pip install jupyter notebook
或者
python -m pip install jupyter
Python3
pip3 install --upgrade pip
sudo pip3 install jupyter notebook
或者
python3 -m pip install jupyter
運行jupyter notebook
jupyter notebook
或者
ipython notebook
三.必要環境配置
ipython profile create
此時會在你的家目錄生成配置文件.ipython/profile_default/ipython_kernel_config.py
運行代碼后自動顯示變量值
直接在該文件的頭部添加代碼
c = get_config()
c.InteractiveShell.ast_node_interactivity = "all"
ipython中文編碼問題
vi ~/.ipython/ipythonrc
readline_parse_and_bind "\M-i": " "
readline_parse_and_bind "\M-o": "\d\d\d\d"
readline_parse_and_bind "\M-I": "\d\d\d\d
注釋掉這3行
使用matplotlib作圖顯示中文
需要設置中文字體,否則中文會亂碼。
import matplotlib.pyplot as plt
plt.rc('font', family='Microsoft YaHei Mono', size=12)
四.基本使用
常用快捷鍵
- 在當前cell的上一層添加cell:A
- 在當前cell的下一蹭添加cell:B
- 雙擊d:刪除當前cell
- 撤銷對某個cell的刪除:z
- 當前的cell進入編輯模式:Enter
- 退出當前cell的編輯模式:Esc
- 執行當前cell並跳到下一個cell:Shift Enter
- 執行當前cell執行后不調到下一個cell:Ctrl Enter
- 向下選擇多個cell:Shift + J 或 Shift + Down
- 向上選擇多個cell:Shift + K 或 Shift + Up
- 合並cell:Shift + M
- 在代碼中查找、替換,忽略輸出:Esc + F
- 在cell和輸出結果間切換:Esc + O
- 快速跳轉到首個cell:Crtl Home
- 快速跳轉到最后一個cell:Crtl End
- m:進入markdown模式,編寫md的文檔進行描述說明
- 為當前的cell加入line number:單L
- 將當前的cell轉化為具有一級標題的maskdown:單1
- 將當前的cell轉化為具有二級標題的maskdown:單2
- 將當前的cell轉化為具有三級標題的maskdown:單3
- 為一行或者多行添加/取消注釋:Crtl /
- 在瀏覽器的各個Tab之間切換:Crtl PgUp和Crtl PgDn
參考
https://www.zybuluo.com/hanxiaoyang/note/534296
https://zhuanlan.zhihu.com/p/26739300?group_id=843868091631955968
https://www.cnblogs.com/Sinte-Beuve/p/5148108.html
https://www.zhihu.com/question/59392251
http://www.jianshu.com/p/2f3be7781451 Anaconda使用總結
JupyterLab安裝使用
JupyterLab是Jupyter Notebook的增強版本,看起來更像是一個IDE。
pip install jupyterlab
安裝早版本的Jupyter Notebook
如果你使用的Jupyter版本早於5.3,那么你還需要運行以下命令來啟動JupyterLab服務組件。
jupyter serverextension enable --py jupyterlab --sys-prefix
運行
使用以下命令運行JupyterLab:
jupyter lab
JupyterLab 會在自動在瀏覽器中打開. See our documentation for additional details.
查看令牌
jupyter notebook list
輸出
http://localhost:8888/?token=c8de56fa... :: /Users/you/notebooks
您可以通過運行以下命令列出當前安裝的擴展:
jupyter labextension list
通過運行以下命令卸載擴展:
jupyter labextension uninstall my-extension
其中my-extension
是擴展名列表中的打印名稱。您也可以使用此命令卸載核心擴展(以后可以隨時重新安裝核心擴展)。
參考
https://jupyterlab.readthedocs.io/en/latest/user/extensions.html
https://github.com/jupyterlab/jupyterlab#getting-help
https://gitter.im/jupyterlab/jupyterlab
http://jupyterlab.github.io/jupyterlab/