1 Anaconda中安裝和配置Jupyter notebook
參考資料:https://www.cnblogs.com/wqbin/p/11996766.html
1.1 安裝jupyter
安裝anaconda環境,激活環境:conda activate py37后,直接執行如下命令
conda install jupyter
1.2 配置jupyter
(1)前置條件:一個配置文件
第一步生成配置文件 jupyter_notebook_config.py
jupyter notebook --generate-config
注意:配置文件位於
(2)生成密碼
第二步bash生成
jupyter notebook password Enter password: xxxx Verify password: xxxx [NotebookPasswordApp] Wrote hashed password to /home/rdev/jupyter/jupyter_notebook_config.json
(3)添加到配置文件
在對應文件夾中找到配置文件,將哈希密碼添加到配置文件 jupyter_notebook_config.py
# ip 設置為 * c.NotebookApp.ip = '*' # 密碼 設置為 sha1 c.NotebookApp.password = u'sha1:xxxxx:xxxxxxxxxxx<your hashed password here>' # 瀏覽器設置不打開 c.NotebookApp.open_browser = False # 設置一個固定的接口 c.NotebookApp.port = 8888
1.3 在Pycharm中使用Jupyter
(1)啟動Jupyter
在Pycharm的終端中輸入:
jupyter notebook
結果如下:說明啟動成功。點擊終端中的鏈接跳轉到瀏覽器,輸入密碼即可在瀏覽器中使用Jupyter
(2)使用Jupyter
在項目中新建ipynb文件
然后點擊配置Jupyter服務器,將上面Pycharm終端中的url復制到其中,在后面追加“?token=你的密碼”
(3)測試
#%% import numpy as np import matplotlib.pyplot as plt x=np.arange(0,2*np.pi,0.01) y=np.sin(x) plt.plot(x,y) plt.show()
2、Pycharm中更換Jupyter notebook背景
參考資料:https://blog.csdn.net/Apple_xiaoli/article/details/104533008
2.1 圖表樣式問題
測試后發現,對於圖表樣式,圖表輸出是白底,同時黑色字體會和背景融為一體,就像這樣:
解決方法:安裝jupyterthemes
在conda中使用命令安裝;
conda install jupyterthemes
然后,在ipynb文件中添加如下代碼:
from jupyterthemes import jtplot jtplot.style() # 使用當前主題樣式進行圖表背景填充
解決后的圖表變為:
2.2 更換主題
在conda中,安裝jupyterthemes后,輸入命令jt -l(這是list)可以查看主題
輸入命令jt -t 主題名 可以使用該主題
瀏覽器中jupyter效果如圖,但是Pycharm中圖表樣式並沒有改變