Python/R/Julia @ iPython/Jupyter notebook @ Ubuntu 20.04
程序员文章站
2022-05-25 20:57:10
...
习惯在 iPython notebook里写实验性的代码(其实Jupyter notebook)。看到 www.jupyter.org 上说可以用其他语言,包括R、Julia、C++、Scheme、Ruby等。本人对R和Julia比较感兴趣,就在 Ubuntu [email protected] 4B上试了一下。
Python @ iPython notebook
这个最简单
$ sudo apt install ipython3 python3-notebook # 安装iPython notebook
$ ipython3 notebook password # 设定登陆密码
$ screen -dmS note
$ screen -r note
$ ipython3 notebook --ip=10.0.0.68 --port=8080 --no-browser
$ Ctrl+a Ctrl+d #以上放在一个screen虚拟终端里跑
R @ iPython notebook
这个有点麻烦,但是Ubuntu已经有对应的软件包。
$ sudo apt install r-base #R基础包,会关联不少包
$ sudo apt install r-cran-irkernel # 也会关联一大堆包
$ sudo R
R> library(IRkernel)
R> IRkernel::installspec(user = FALSE) # 安装到全局,而不是用户
Error in IRkernel::installspec(user = FALSE) :
jupyter-client has to be installed but “jupyter kernelspec --version” exited with code 1.
操作最后出现错误,但是使用无问题。
Julia @ iPython notebook
Ubuntu 20.04封装的Julia包不多。需要官方源之外的支持。
$ sudo julia
_
_ _ _(_)_ | Documentation: https://docs.julialang.org
(_) | (_) (_) |
_ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 1.4.1
_/ |\__'_|_|_|\__'_| | Ubuntu ⛬ julia/1.4.1+dfsg-1
|__/ |
julia> #按 ] 进入pkg模式,Ctrl+c退回
(@v1.4) pkg> add IJulia # 参考https://github.com/JuliaLang/IJulia.jl
然后重新启动 iPython notebook 就可以建立Python/R/Julia不同的notebook了。
Stata @ iPython notebook
没有成功。原因很显然。
[email protected]:~# pip3 install stata_kernel
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting stata_kernel
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/b9/b1/2dffa47989d0777fe49c655dd9ea5d62acbfb887f84eff779974b11020b9/stata_kernel-1.12.2.tar.gz (90 kB)
|████████████████████████████████| 90 kB 473 kB/s
Requirement already satisfied: IPython>=6.5.0 in /usr/lib/python3/dist-packages (from stata_kernel) (7.13.0)
Requirement already satisfied: beautifulsoup4>=4.6.3 in /usr/lib/python3/dist-packages (from stata_kernel) (4.8.2)
Requirement already satisfied: ipykernel>=4.8.2 in /usr/lib/python3/dist-packages (from stata_kernel) (5.2.0)
Requirement already satisfied: jupyter_client>=5.2.3 in /usr/lib/python3/dist-packages (from stata_kernel) (6.1.2)
Requirement already satisfied: packaging>=17.1 in /usr/lib/python3/dist-packages (from stata_kernel) (20.3)
Requirement already satisfied: pandas>=0.22.0 in /usr/lib/python3/dist-packages (from stata_kernel) (0.25.3)
Requirement already satisfied: pexpect>=4.6.0 in /usr/lib/python3/dist-packages (from stata_kernel) (4.6.0)
Requirement already satisfied: pillow>=5.2.0 in /usr/lib/python3/dist-packages (from stata_kernel) (7.0.0)
Requirement already satisfied: pygments>=2.2.0 in /usr/lib/python3/dist-packages (from stata_kernel) (2.3.1)
Requirement already satisfied: requests>=2.19.1 in /usr/lib/python3/dist-packages (from stata_kernel) (2.22.0)
Building wheels for collected packages: stata-kernel
Building wheel for stata-kernel (setup.py) ... done
Created wheel for stata-kernel: filename=stata_kernel-1.12.2-py3-none-any.whl size=89548 sha256=692a182dbb256cf245da15f17cd39ec3a290fa072f945e2d1da2e666e233e857
Stored in directory: /root/.cache/pip/wheels/d6/30/a0/c4c88519b498f8f2965f6983b4b86a69f07bee00c7d35abb16
Successfully built stata-kernel
Installing collected packages: stata-kernel
Successfully installed stata-kernel-1.12.2
[email protected]:~# python -m stata_kernel.install
Cannot import kernel
Installing Jupyter kernel spec
WARNING: Could not find Stata path.
Refer to the documentation to see how to set it manually:
https://kylebarron.dev/stata_kernel/using_stata_kernel/configuration
配置代码自动提示
$ sudo pip3 install jupyter_contrib_nbextensions
$ sudo jupyter contrib nbextension install
下一篇: PHP学习笔记之二 php入门知识