簡(jiǎn)介
Jupyter是一個(gè)強(qiáng)大的開(kāi)源交互式開(kāi)發(fā)環(huán)境,它可以支持多種語(yǔ)言的編寫(xiě),能夠交互式的分步執(zhí)行不同的命令并顯示相應(yīng)的結(jié)果,非常便于網(wǎng)頁(yè)的展示和教學(xué)過(guò)程。在數(shù)據(jù)挖掘、數(shù)據(jù)分析與可視化和機(jī)器學(xué)習(xí)等領(lǐng)域有著廣泛的應(yīng)用。
Jupyter的安裝
Jupyter既可以使用pip命令直接安裝,也可以使用conda包來(lái)進(jìn)行安裝。這里推薦使用Anaconda環(huán)境來(lái)安裝Jupyter,默認(rèn)情況下Anaconda環(huán)境中已經(jīng)安裝好了Jupyter程序。
image.png
# 下載并安裝Anaconda環(huán)境
wget https://repo.anaconda.com/archive/Anaconda3-2019.03-Linux-x86_64.sh
chmod +x Anaconda3-2019.03-Linux-x86_64.sh
bash ./Anaconda3-2019.03-Linux-x86_64.sh
生成Jupyter notebook的配置文件
安裝好Anaconda環(huán)境后,會(huì)在自己的home目錄下生成一個(gè)anaconda3文件夾,添加相應(yīng)的文件路徑到環(huán)境變量中就可以直接使用Jupyter程序了。
# 添加環(huán)境變量
vim ~/.bash_profile
export PATH="~/anaconda3/bin:$PATH"
source ~/.bash_profile
# 查看使用說(shuō)明
jupyter -h
usage: jupyter [-h] [--version] [--config-dir] [--data-dir] [--runtime-dir]
[--paths] [--json]
[subcommand]
Jupyter: Interactive Computing
positional arguments:
subcommand the subcommand to launch
optional arguments:
-h, --help show this help message and exit
--version show the jupyter command's version and exit
--config-dir show Jupyter config dir
--data-dir show Jupyter data dir
--runtime-dir show Jupyter runtime dir
--paths show all Jupyter paths. Add --json for machine-readable
format.
--json output paths as machine-readable json
# 生成Jupyter notebook的配置文件
jupyter notebook --generate-config
運(yùn)行完jupyter notebook --generate-config命令后,會(huì)在自己的home目錄下生成一個(gè).jupyter的隱藏文件夾,文件夾中有一個(gè)jupyter_notebook_config.py配置文件。
打開(kāi)python或ipython生成密鑰
from notebook.auth import passwd
passwd()
# 設(shè)置登錄密碼,兩次輸入密碼,生成秘鑰,并復(fù)制你的秘鑰
# 秘鑰開(kāi)頭:sha1……
修改Jupyter notebook配置文件
vim ~/.jupyter/jupyter_notebook_config.py
# 找到相應(yīng)的位置,去除注釋并修改
c.NotebookApp.ip='xxx.xxx.xxx.xx' # 設(shè)置服務(wù)器對(duì)應(yīng)的ip地址
c.NotebookApp.password = u'sha:ce......' # 設(shè)置剛才復(fù)制的那個(gè)密鑰'
c.NotebookApp.open_browser = False # 禁止自動(dòng)打開(kāi)瀏覽器
c.NotebookApp.port =1220 #隨便指定一個(gè)端口
在服務(wù)器端啟動(dòng)Jupyter notebook
jupyter notebook
# 后臺(tái)啟動(dòng)持續(xù)運(yùn)行
nohup jupyter notebook &
在瀏覽器中輸入相應(yīng)的ip地址和端口

image.png