一、Jupyter Notebook遠程訪問服務器
記錄一下,用采用jupyter遠程連接服務器,然后在本地的notebook上面調代碼:
step1: 首先輸入ipython生成秘鑰
在這個步驟里面,需要自己設定一下本地登錄jupyter notebook的密碼:
$ ipython
In [1]: from notebook.auth import passwd
In [2]: passwd()
Enter password:
Verify password:
Out[2]: 'sha1:f4eeddfa2f16:9ac17aa43b249400e313851bf95efea2a800e5fe'
In [3]: exit()
step2:生成一個jupyter notebook的config文件,注意這里命令中--個數(shù),generate前面是兩個-,config前面就是一個-。
$ jupyter notebook --generate-config
step3:修改配置文件config.py
$ vim ~/.jupyter/jupyter_notebook_config.py
在該配置文件里面加上
...省略了前面的配置內容
#------------------------------------------------------------------------------
# KernelSpecManager(LoggingConfigurable) configuration
#------------------------------------------------------------------------------
## If there is no Python kernelspec registered and the IPython kernel is
# available, ensure it is added to the spec list.
#c.KernelSpecManager.ensure_native_kernel = True
## The kernel spec class. This is configurable to allow subclassing of the
# KernelSpecManager for customized behavior.
#c.KernelSpecManager.kernel_spec_class = 'jupyter_client.kernelspec.KernelSpec'
## Whitelist of allowed kernel names.
#
# By default, all installed kernels are allowed.
#c.KernelSpecManager.whitelist = set()
#
c.NotebookApp.ip='*'
c.NotebookApp.password = u'sha1:f4eeddfa2f16:9ac17aa43b249400e313851bf95efea2a800e5fe'
c.NotebookApp.open_browser = False
c.NotebookApp.port =2333 # 設置端口
step4:啟動jupyter notebook
$ jupyter notebook
啟動之后在游覽器上面輸入http://服務器地址:端口號
http://168.43.2.14:23333
然后會提醒你輸入第一步里面設置的密碼,輸入之后就進去了:

之后就可以愉快的在本地的jupyter notebook上面愉快的進行遠程的操作服務器了。
二、并修改Jupyter Notebook主題
長時間看白色的jupyter notebook有點傷眼睛,所以想辦法將jupyter notebook的背景顏色給改調整了一下,具體的步驟如下:
step1:在終端輸入:
pip install --upgrade jupyterthemes
顧名思義,該命令就是來給jupyter notebook給安裝一些主題的,安裝完畢了之后
step2:我們可以看看所有的主題是什么
jt -l
上述命令就是顯示出我們可以利用的主題,總共有幾個主題如下:
Available Themes:
chesterish
grade3
gruvboxd
gruvboxl
monokai
oceans16
onedork
solarizedd
solarizedl
step 3: 選取主題
下面以例子來說明選取主題,假如我選取的主題是monokai
jt -t monokai chesterish
使用上述命令之后,在終端輸入
jupyter notebook
這個時候,你就會發(fā)現(xiàn),jupyter notebook的主題顏色發(fā)生了改變。

具體還有很多的參數(shù)可以設置,可以參考GitHub上面的配置方式https://github.com/dunovank/jupyter-themes
在安裝過程中,也遇到了一個小問題:
KeyError: 'allow_remote_access'
解決之道,參考參考資料第二個博客,看了解決方法之后,就明白配置出現(xiàn)了一點問題,只要在jupyter_notebook_config.py里面加上一行代碼就能搞定了
vim ~/.jupyter/jupyter_notebook_config.py
在jupyter_notebook_config.py里面加上一下的命令,問題就解決了
c.NotebookApp.allow_remote_access = True
好了,先就寫到這里了,想要換個jupyter notebook風格的小伙伴,趕緊行動起來把。
三、Jupyter Notebook中的一些常用的魔法命令
3.1 %run
目錄樹
└── test
└── hello.py
我們在jupyter notebook中運行hello.py文件,采用的是相對的路徑的寫法。
%run test/hello.py
# 結果就是hello world!了。
3.2 %timeit
這個魔法命令就是用來測試運行一行代碼所要消耗的時間了
3.3 %time
這個魔法命令就是用來測試運行一個模塊代碼所要消耗的時間了
其他的魔法命令見%lsmagic
參考資料
1、https://blog.csdn.net/Mr_Cat123/article/details/79181231
2、https://blog.csdn.net/w5688414/article/details/82927564
3、https://github.com/dunovank/jupyter-themes