美文网首页
centos搭建Jupyter Notebook

centos搭建Jupyter Notebook

作者: 秦淮河的桨 | 来源:发表于2019-05-28 00:30 被阅读0次

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下载。

whereiswhich查找文件, find [path] -name xxx查找指定目录下的文件

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

安装jupyter

  1. 下载Anaconda最新版本,省事。在官网找到下载链接,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
```
中间需要确定时确定即可,等待安装完成,会自动写入环境变量。
```sh
conda --version
jupyter --version
```
  1. 然后按照官网步骤,设置config
jupyter notebook --generate-config
# 会生成config文件为 .jupyter/jupyter_notebook_config.py
设置密码
```
from notebook.auth import passwd
passwd()
# 会生成类似 sha1:xxxxxxxxxxxxxxxxxxx, 需要记一下
```

然后编辑 config文件
```
vim .jupyter/jupyter_notebook_config.py
```

修改这些行,去掉注释,填相应值。其他选项也可以自己设置
```
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 # 查看防火墙状态
    
  2. 启动server,jupyter notebook。如果需要后台启动,运行
    nohup jupyter notebook > jupyter.log 2>&1 &

安装其他kernel

主要根据 [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. 准备工作,安装环境。
    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,设置好环境变量,

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环境启动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,发现了

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

现在,看一下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这三个文件夹复制到.ipython/kernels/

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

完成。


DigitalOcean 优惠码,注册充值 5 送100,链接一 链接二

Lastly, welcome to follow me on github

相关文章

网友评论

      本文标题:centos搭建Jupyter Notebook

      本文链接:https://www.haomeiwen.com/subject/svultctx.html