欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

ubuntu16.04安裝jupyternotebook使用與進(jìn)階

一、Jupyter Notebook簡(jiǎn)介

Jupyter Notebook(此前被稱為 IPython notebook)是一個(gè)交互式筆記本,支持運(yùn)行 40 多種編程語(yǔ)言。
Jupyter Notebook 的本質(zhì)是一個(gè) Web 應(yīng)用程序,便于創(chuàng)建和共享文學(xué)化程序文檔,支持實(shí)時(shí)代碼,數(shù)學(xué)方程,可視化和 markdown。 用途包括:數(shù)據(jù)清理和轉(zhuǎn)換,數(shù)值模擬,統(tǒng)計(jì)建模,機(jī)器學(xué)習(xí)等等;
是一款非常好用的基于web方式使用python的工具;
支持windows 與linux系統(tǒng),本次以u(píng)buntu 16.04 python3.5.2為例,安裝演示;
相關(guān)配置及更高級(jí)的玩法請(qǐng)參考官方文檔

成都創(chuàng)新互聯(lián)公司-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比彌渡網(wǎng)站開(kāi)發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫(kù),直接使用。一站式彌渡網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋彌渡地區(qū)。費(fèi)用合理售后完善,十年實(shí)體公司更值得信賴。

以上的操作是針對(duì)本機(jī)的python3操作,如果想在虛擬的python環(huán)境中操作請(qǐng)參考搭建python虛擬環(huán)境
其他的步驟是 一樣的;

二、安裝

1、pip安裝

sudo python3 -m pip install --upgrade pip
sudo python3 -m pip install jupyter

2、簡(jiǎn)單使用
默認(rèn)安裝好后直接在命令行里輸入
$ jupyter notebook
類似如下圖:
ubuntu 16.04安裝jupyter notebook使用與進(jìn)階
如上圖,新建-->Python3 創(chuàng)建如下圖交互式帶提示的python命令行
ubuntu 16.04安裝jupyter notebook使用與進(jìn)階
輸入print("Hellow world") 點(diǎn)運(yùn)行即可執(zhí)行看到效果;

新建終端時(shí),直接以登錄系統(tǒng)身份登錄系統(tǒng)終端如圖:
ubuntu 16.04安裝jupyter notebook使用與進(jìn)階

至次jupyter notebook的簡(jiǎn)單安裝使用就完成了,沒(méi)錯(cuò)就是這么簡(jiǎn)單~
然而這么好的工具,這么方便的操作只能運(yùn)行在本地?如果在局域網(wǎng)或端口映射后能在外面操作,通過(guò)密碼登錄;豈不是很完美?查看了官方網(wǎng)站教程,別說(shuō)還真有;下面就配置下把jupyter notebook開(kāi)放在本地的任何接口上,并且配置https形式,這樣傳輸就安全啦~

三、jupyter notebook使用進(jìn)階

1、配置密碼

$ jupyter notebook password
Enter password:  ****
Verify password: ****

以上操作會(huì)在我的家目錄下生成 /home/san/.jupyter/jupyter_notebook_config.json
文件,密碼以hash保存如下:

$  /home/san/.jupyter/jupyter_notebook_config.json
{
  "NotebookApp": {
    "password": "sha1:74432c61ae9b:26c35e70239jfe7e3dc4b177d140d4ac7f560e1f"
  }
}

些時(shí)結(jié)束之前的jupyter notebook實(shí)例再次運(yùn)行,會(huì)提示輸入密碼,如圖:
ubuntu 16.04安裝jupyter notebook使用與進(jìn)階
此時(shí)只有輸入正確的密碼后才能正常登錄使用jupyter 啦!

2、偵聽(tīng)非本地接口
默認(rèn)出于安全jupyter只運(yùn)行偵聽(tīng)在本地,想把這么好的功能放在網(wǎng)絡(luò)上使用需要生成添加配置文件

$ jupyter notebook --generate-config

運(yùn)行后會(huì)在家目錄.jupyter/下生成jupyter_notebook_config.py文件
修改內(nèi)容如下:

c.NotebookApp.ip = '0.0.0.0'
c.NotebookApp.open_browser = False 
c.NotebookApp.password = "sha1:74432c61ae9b:26c35e70239jfe7e3dc4b177d140d4ac7f560e1f"
c.NotebookApp.port = 8888

注意:按官方的c.NotebookApp.ip = '*' 報(bào)錯(cuò),換成0.0.0.0則可以
可以看到不僅可以自定義偵聽(tīng)地址,還可以修改偵聽(tīng)端口;

$ netstat -ntpul |grep python3
tcp        0      0 0.0.0.0:8888            0.0.0.0:*               LISTEN      2403/python3

此時(shí)就可以通過(guò)本地的ip或loclahost :8888訪問(wèn)啦

3、jupyter配置https
創(chuàng)建私鑰并自簽:

$ openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout mykey.key -out mycert.pem

運(yùn)行以上命令如下需要填寫相關(guān)信息如圖:
ubuntu 16.04安裝jupyter notebook使用與進(jìn)階

以https方式啟動(dòng):

$ jupyter notebook --certfile=mycert.pem --keyfile mykey.key
[I 13:30:22.165 NotebookApp] 啟動(dòng)notebooks 在本地路徑: /home/dongyc/ipython
[I 13:30:22.165 NotebookApp] 本程序運(yùn)行在: https://(san-Vostro-3660 or 127.0.0.1):8888/
[I 13:30:22.165 NotebookApp] 使用control-c停止此服務(wù)器并關(guān)閉所有內(nèi)核(兩次跳過(guò)確認(rèn)).

注意:證書文件需要絕對(duì)路徑;
此時(shí)可以使用https://10.8.11.65:8888 或https://localhost:8888進(jìn)行訪問(wèn)啦 如圖:
ubuntu 16.04安裝jupyter notebook使用與進(jìn)階

到這里jupyter notebook基本配置完成了,但有一個(gè)問(wèn)題,每次啟動(dòng)jupyter都要切換到一個(gè)指定目錄(就是上圖中文件列出來(lái)的內(nèi)容所在目錄);而且還要占用一個(gè)終端;
還是搞一個(gè)后臺(tái)服務(wù),開(kāi)機(jī)自動(dòng)運(yùn)行吧,以下的內(nèi)容是官方?jīng)]有的,本人自己搗鼓的;

4、jupyter服務(wù)

#!/bin/bash
# author: by san at 20180929
### BEGIN INIT INFO
# Provides:             jupyter 
# Required-Start:       $syslog $remote_fs
# Required-Stop:        $syslog $remote_fs
# Should-Start:         $local_fs
# Should-Stop:          $local_fs
# Default-Start:        2 3 4 5 
# Default-Stop:         0 1 6
# Short-Description:    jupyter notebook deamon 
# Description:          jupyter notebook with https deamon
### END INIT INFO

. /home/san/functions      # 這個(gè)類似redhat系列上的/etc/init.d/functions shell庫(kù) 你的系統(tǒng)自行找,如找不到請(qǐng)聯(lián)系我
prog=jupyter
pidfile=${PIDFILE-/tmp/jupyter.pid}
lockfile=${LOCKFILE-/tmp/jupyter}
jupyter="/usr/local/bin/jupyter"     # 如果是虛擬python環(huán)境請(qǐng)?zhí)顚懻_的路徑
RETVAL=0

START(){
if [ ! -f ${pidfile} ]; then
cd /home/san/ipython 
echo -n $"Stopping jupyter notebook:"
nohup ${jupyter}  notebook  --certfile=/home/san/mycert.pem --keyfile /home/san/mykey.key >/tmp/jupyter.log 2>&1 &
 [ "$?" -eq 0 ] && success $"$base startup" || failure $"$base startup"
 jupyter_pid=$(ps aux |grep jupyter |grep -v grep|awk '{print $2}')
 echo $jupyter_pid >$pidfile
  RETVAL=$?
    echo
 [ $RETVAL = 0 ] && touch ${lockfile}
     return $RETVAL
else
  status -p ${pidfile}
  exit 0
 fi

}

STOP(){
        echo -n $"Stopping jupyter notebook:"
        nohup kill -15 $(ps aux |grep jupyter |grep -v grep|awk '{print $2}')  >/dev/null 2>&1 &
        [ "$?" -eq 0 ] && success $"$base startup" || failure $"$base startup"
        echo
        [ -f ${pidfile} ] && rm -rf ${pidfile}
        [ -f ${lockfile} ] && rm -rf ${lockfile}
}

case $1 in
    start)
    START
    ;;
    stop)
    STOP
    ;;
    restart)
    STOP
    START
    ;;
    status)
    status -p ${pidfile} $prog
    ${jupyter} notebook list
    RETVAL=$?
    ;;
    *)
   echo "USAGE:start|stop|restart"
    ;;
esac

添加可執(zhí)行權(quán)限

$ chmod +x /etc/init.d/jupyter

測(cè)試腳本 如圖:
ubuntu 16.04安裝jupyter notebook使用與進(jìn)階
可以發(fā)現(xiàn)腳本可以執(zhí)行;會(huì)自動(dòng)讀取當(dāng)前登錄系統(tǒng)用戶的家目錄下.jupyter下的配置文件;官方說(shuō)把密鑰和簽名證書配置到配置文件中,但我測(cè)試下來(lái)找不到證書,所以把證書當(dāng)啟動(dòng)參數(shù)放到,服務(wù)腳本中了,這是正常的;
系統(tǒng)重啟會(huì)自動(dòng)啟動(dòng)jupyter notebook 偵聽(tīng)在8888上,系統(tǒng)關(guān)閉時(shí),會(huì)自動(dòng)關(guān)閉jupyter服務(wù); upyter notebook可以運(yùn)行多實(shí)例;即默認(rèn)隨機(jī)啟動(dòng)偵聽(tīng)在8888 再次在終端上執(zhí)行時(shí)會(huì)偵聽(tīng)在8889端口 如圖:
ubuntu 16.04安裝jupyter notebook使用與進(jìn)階

此時(shí)你會(huì)發(fā)現(xiàn) 一臺(tái)服務(wù)器可以開(kāi)多個(gè)實(shí)例,給多個(gè)人測(cè)試使用~是不是很方便很好用?趕緊試試吧~

本文標(biāo)題:ubuntu16.04安裝jupyternotebook使用與進(jìn)階
標(biāo)題網(wǎng)址:http://chinadenli.net/article4/goshoe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供用戶體驗(yàn)微信小程序軟件開(kāi)發(fā)域名注冊(cè)品牌網(wǎng)站制作云服務(wù)器

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)