在服務(wù)器上使用jupyter

轉(zhuǎn)載自在服務(wù)器上配置jupyter, 遠程登錄

1.安裝與配置

第一步:安裝jupyter
參考:Ubuntu 安裝 Anaconda3 詳細步驟

或者可以使用:

pip3 install jupyter (此處使用的是python3)

第二步:生成配置文件jupyter notebook --generate-config

第三步:生成密鑰 打開python3 ,然后輸入

1.  from notebook.auth import passwd  
2.  passwd()  
3.  此時會讓你兩次輸入密碼,然后就會生成秘鑰  
4.  ************  

修改配置文件

sudo vi ~/.jupyter/jupyter_notebook_config.py
大約在200行的位置始藕,找到下面配置

1. c.NotebookApp.ip='*' # 就是設(shè)置所有ip皆可訪問

1. c.NotebookApp.ip='0.0.0.0'                         
#  "start of jupyter notebook server on ip adress '0.0.0.0' instead of default '*' which is no longer supported this is probably needed only on a temporary basis see also
https://github.com/jupyter/docker-stacks/issues/718
https://github.com/ageron/handson-ml/pull/317/commits") 
2.  c.NotebookApp.password = u'sha:ce...       # 剛才復(fù)制的那個密文'  
3.  c.NotebookApp.open_browser = False       # 禁止自動打開瀏覽器  
4.  c.NotebookApp.port =8888                         #隨便指定一個端口  

第四步:配置一下路由器的端口轉(zhuǎn)發(fā),

第五步:在服務(wù)器端啟動 jupyter notebook

第六步:本地地址欄輸入服務(wù)器ip:8888 就OK了

2.打開 Jupyter Notebook

打開 notebook 的方法非常簡單湿酸,只需在終端輸入

ipython notebook

3.退出

在ubuntu終端運行jupyter notebook后打開了jupyter的網(wǎng)頁,在關(guān)閉jupyter的網(wǎng)頁后如何在ubuntu終端退出jupyter notebook重新進入命令輸入行呢灭美?

同時按下ctrl和C鍵推溃,然后按照下面終端界面提示操作就可以了。


pip查看已安裝的包

# pip show --files SomePackage
  Name: SomePackage
  Version: 1.0
  Location: /my/env/lib/pythonx.x/site-packages
  Files:
   ../somepackage/__init__.py
   [...]

參考pip安裝使用詳解

4.安裝python2 kernal

sudo python2 -m pip install --user --ignore-installed python-dateutil ipykernel

jupyter kernel查看內(nèi)核

jupyter kernelspec list

卸載內(nèi)核

jupyter kernelspec remove kernelname

5. ubuntu 中jupyter notebook python2&3 并存使用

在終端輸入

$python2 -m pip install ipykernel
$python2 -m ipykernel install --user

$python3 -m pip install ipykernel
$python3 -m ipykernel install --user

----------------------
Kernels for Python 2 and 3

出現(xiàn)問題:

Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/usr/local/lib/python2.7/dist-packages/ipykernel_launcher.py", line 15, in <module>
    from ipykernel import kernelapp as app
  File "/usr/local/lib/python2.7/dist-packages/ipykernel/__init__.py", line 2, in <module>
    from .connect import *
  File "/usr/local/lib/python2.7/dist-packages/ipykernel/connect.py", line 14, in <module>
    from IPython.paths import get_ipython_dir
ImportError: No module named paths

solution

這是由于系統(tǒng)自帶ipython版本與jupyter沖突届腐。

This is because of version conflict of ipython installed by apt-get package manager and ipython by pip:

so uninstall all versions of ipython from apt-get as follows:

sudo apt-get remove ipython ipython-notebook ipython-notebook-common

also remove from pip: both jupyter and ipython

sudo pip uninstall jupyter 
sudo pip uninstall ipython  

As ipython is part of jupyter, so just reinstall jupyter

sudo pip install jupyter 

This should help!!!

附注:使用Anaconda管理不同版本

The idea here is to install multiple ipython kernels. Here are instructions for anaconda. If you are not using anaconda, I recently added instructions using pure virtualenvs.

Anaconda 4.1.0

Since version 4.1.0, anaconda includes a special package nb_conda_kernels that detects conda environments with notebook kernels and automatically registers them. This makes using a new python version as easy as creating new conda environments:

conda create -n py27 python=2.7 ipykernel
conda create -n py36 python=3.6 ipykernel

After a restart of jupyter notebook, the new kernels are available over the graphical interface. Please note that new packages have to be explicitly installed into the new enviroments. The Managing environments section in conda's docs provides further information.

Manually registering kernels

Users who do not want to use nb_conda_kernels or still use older versions of anaconda can use the following steps to manually register ipython kernels.

configure the python2.7 environment:

conda create -n py27 python=2.7
source activate py27
conda install notebook ipykernel
ipython kernel install --user

configure the python3.6 environment:

conda create -n py36 python=3.6
source activate py36
conda install notebook ipykernel
ipython kernel install --user

After that you should be able to choose between python2
and python3 when creating a new notebook in the interface.

Additionally you can pass the --name and --display-name options to ipython kernel install if you want to change the names of your kernels. See ipython kernel install --help for more informations.

6. Jupyter使用

參考Jupyter Notebook使用筆記(一)

兩種模式

Command mode 和 Edit mode美莫。 在一個cell中页眯,按下Enter,進入Edit模式,按下Esc,進入Command 模式

運行當(dāng)前cell厢呵,并移動到下一個Cell

在一個cell中(在command模式下),  Shift + Enter  

創(chuàng)建Cell

在一個cell中(在command模式下)
1\. 按下 a ,即可在這個cell之前創(chuàng)建一個新的cell窝撵;
2\. 按下 b,即可在這個cell之后創(chuàng)建一個新的cell;

Cell中 Code 和 Markdown的切換

在一個cell中(在command模式下)
1\. 按下 y, 進入Code;
2\. 按下m, 進入Markdown;

顯示Cell中的行數(shù)

在一個cell中(在command模式下),按下 l

刪除Cell

在一個cell中(在command模式下), 按兩次 d

保存Notebook

在一個cell中(在command模式下), 按下 s

啟動命令面板

在一個cell中(在command模式下), 按下 Ctrl + Shift + P 
界面中的小鍵盤也可以啟動:

可以通過這個命令面板快速的執(zhí)行命令襟铭。比如我這里將一個cell移動到它下一個cell的下面:在一個cell中(在command模式下)碌奉,然后按下 Ctrl + Shift + P ,輸入 move 寒砖,鍵盤方向鍵選擇要執(zhí)行的命令即可赐劣,然后按下回車即可執(zhí)行。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末哩都,一起剝皮案震驚了整個濱河市魁兼,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌漠嵌,老刑警劉巖孝偎,帶你破解...
    沈念sama閱讀 218,036評論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件代箭,死亡現(xiàn)場離奇詭異惜辑,居然都是意外死亡凳忙,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,046評論 3 395
  • 文/潘曉璐 我一進店門约炎,熙熙樓的掌柜王于貴愁眉苦臉地迎上來植阴,“玉大人,你說我怎么就攤上這事圾浅÷邮郑” “怎么了?”我有些...
    開封第一講書人閱讀 164,411評論 0 354
  • 文/不壞的土叔 我叫張陵狸捕,是天一觀的道長惨撇。 經(jīng)常有香客問我,道長府寒,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,622評論 1 293
  • 正文 為了忘掉前任报腔,我火速辦了婚禮株搔,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘纯蛾。我一直安慰自己纤房,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 67,661評論 6 392
  • 文/花漫 我一把揭開白布翻诉。 她就那樣靜靜地躺著炮姨,像睡著了一般捌刮。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上舒岸,一...
    開封第一講書人閱讀 51,521評論 1 304
  • 那天绅作,我揣著相機與錄音,去河邊找鬼蛾派。 笑死俄认,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的洪乍。 我是一名探鬼主播眯杏,決...
    沈念sama閱讀 40,288評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼壳澳!你這毒婦竟也來了岂贩?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,200評論 0 276
  • 序言:老撾萬榮一對情侶失蹤巷波,失蹤者是張志新(化名)和其女友劉穎萎津,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體褥紫,經(jīng)...
    沈念sama閱讀 45,644評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡姜性,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,837評論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了髓考。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片部念。...
    茶點故事閱讀 39,953評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖氨菇,靈堂內(nèi)的尸體忽然破棺而出儡炼,到底是詐尸還是另有隱情,我是刑警寧澤查蓉,帶...
    沈念sama閱讀 35,673評論 5 346
  • 正文 年R本政府宣布乌询,位于F島的核電站,受9級特大地震影響豌研,放射性物質(zhì)發(fā)生泄漏妹田。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,281評論 3 329
  • 文/蒙蒙 一鬼佣、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧霜浴,春花似錦晶衷、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,889評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽税迷。三九已至,卻和暖如春锹漱,著一層夾襖步出監(jiān)牢的瞬間箭养,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,011評論 1 269
  • 我被黑心中介騙來泰國打工凌蔬, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留露懒,地道東北人。 一個月前我還...
    沈念sama閱讀 48,119評論 3 370
  • 正文 我出身青樓砂心,卻偏偏與公主長得像懈词,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子辩诞,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 44,901評論 2 355

推薦閱讀更多精彩內(nèi)容