centos搭建Jupyter Notebook

centos搭建Jupyter Notebook, 添加多語言支持(R,Ruby,Octave,JS,Java,C++).

https://foreti.me/2018/07/06/centos-jupyter-notebook/


image

常用命令

主要熟悉常用命令,
wget [url]下載,

tar -xvf解壓.tar.gz,

使用yum包管理工具yum search xx搜索, yum install xx下載。

whereis,which查找文件, find [path] -name xxx查找指定目錄下的文件

ps -ef | grep jupyter 查看jupyter運行的pid

安裝jupyter

  1. 下載Anaconda最新版本,省事。在官網(wǎng)找到下載鏈接,python3.6版本,然后
wget https://repo.anaconda.com/archive/Anaconda3-5.2.0-Linux-x86_64.sh 
然后運行腳本
```sh
bash Anaconda3-3-5.2.0-Linux-x86_64.sh
```
中間需要確定時確定即可,等待安裝完成,會自動寫入環(huán)境變量。
```sh
conda --version
jupyter --version
```
  1. 然后按照官網(wǎng)步驟,設(shè)置config
jupyter notebook --generate-config
# 會生成config文件為 .jupyter/jupyter_notebook_config.py
設(shè)置密碼
```
from notebook.auth import passwd
passwd()
# 會生成類似 sha1:xxxxxxxxxxxxxxxxxxx, 需要記一下
```

然后編輯 config文件
```
vim .jupyter/jupyter_notebook_config.py
```

修改這些行,去掉注釋,填相應(yīng)值。其他選項也可以自己設(shè)置
```
c.NotebookApp.password = 'sha1:xxxxxxxxxxxxxxxxxxx'
c.NotebookApp.ip = '*'
c.NotebookApp.open_browser = False
c.NotebookApp.port = 8888
```
  1. 開放和重啟防火墻
    centos7:

    firewall-cmd --zone=public --add-port=8888/tcp --permanent # 永久開放8888端口
    firewall-cmd --reload # 重啟firewall
    firewall-cmd --list-ports # 查看開放端口
    

    centos6:

    /sbin/iptables -I INPUT -p tcp --dport 8888 -j ACCEPT # 開放8888端口
    /etc/rc.d/init.d/iptables save # 保存
    service iptables status # 查看防火墻狀態(tài)
    
  2. 啟動server,jupyter notebook。如果需要后臺啟動,運行
    nohup jupyter notebook > jupyter.log 2>&1 &

安裝其他kernel

主要根據(jù) [Jupyter kernels wiki](https://github.com/jupyter/jupyter/wiki/Jupyter-kernels

py2.7

conda create -n ipykernel_py2 python=2 ipykernel
source activate ipykernel_py2
python -m ipykernel install --user

ruby

iruby, ruby需要版本大于2.1

  1. 準備工作,安裝環(huán)境。
    yum 下載的可能不是最新的ruby,所以用
sudo yum install -y git-core ruby-devel ruby zlib zlib-devel gcc-c++ patch readline readline-devel libyaml-devel libffi-devel openssl-devel make
  1. ruby kernel需要ZeroMQ
sudo yum install zeromq-devel zeromq czmq
gem install cztop rbczmq ffi_rzmq
  1. 安裝iruby kernel
gem install cztop iruby
iruby register --force

R

按照irkernel的安裝步驟,
或者直接

conda install -c r r-essentials

octave

pip

pip install octave_kernel

或者conda

conda config --add channels conda-forge
conda install octave_kernel

js

首先安裝nodejs和npm,然后

npm install -g ijavascript
ijsinstall

java

IJava ,需要安裝java 9或10,設(shè)置好環(huán)境變量,

export JAVA_HOME=/usr/java/jdk-10.0.1/
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$JAVA_HOME/bin:$PATH

然后

git clone https://github.com/SpencerPark/IJava.git --depth 1
cd IJava/
chmod u+x gradlew
./gradlew installKernel

c++

xues-cling

conda create -n cling
source activate cling
conda install xeus-cling notebook -c QuantStack -c conda-forge

有個問題是需要切換到cling環(huán)境啟動jupyter才會有c++的kernel,找了一下cling 的kernel文件

find anaconda3/envs/cling -name kernels

輸出

anaconda3/envs/cling/lib/python3.6/site-packages/notebook/services/kernels
anaconda3/envs/cling/lib/python3.6/site-packages/notebook/static/services/kernels
anaconda3/envs/cling/share/jupyter/kernels

進入到/share/jupyter/kernels,發(fā)現(xiàn)了

cd anaconda3/envs/cling/share/jupyter/kernels
ll

輸出

total 16
drwxr-xr-x 2 root root 4096 Jul  5 14:48 python3
drwxr-xr-x 2 root root 4096 Jul  5 14:48 xeus-cling-cpp11
drwxr-xr-x 2 root root 4096 Jul  5 14:48 xeus-cling-cpp14
drwxr-xr-x 2 root root 4096 Jul  5 14:48 xeus-cling-cpp17

現(xiàn)在,看一下jupyter kernel的文件目錄在哪

jupyter kernelspec list

輸出

Available kernels:
  java                /root/.ipython/kernels/java
  ruby                /root/.ipython/kernels/ruby
  ir                  /root/.local/share/jupyter/kernels/ir
  javascript          /root/.local/share/jupyter/kernels/javascript
  python2             /root/.local/share/jupyter/kernels/python2
  python3             /root/.local/share/jupyter/kernels/python3
  octave              /root/anaconda3/share/jupyter/kernels/octave
  bash                /usr/local/share/jupyter/kernels/bash

確定是.ipython/kernels/的這一個。

xeus-cling-cpp11 xeus-cling-cpp14 xeus-cling-cpp17這三個文件夾復(fù)制到.ipython/kernels/

cp xeus-cling-cpp11 .ipython/kernels/
cp xeus-cling-cpp14 .ipython/kernels/
cp xeus-cling-cpp17 .ipython/kernels/

完成。



DigitalOcean 優(yōu)惠碼,注冊充值 5 送100,鏈接一 鏈接二

Lastly, welcome to follow me on github

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容