jupyter notebook配置IRkernel(mac版)

目录

第一步

第二步

jupyter notebook使用R实例


windows下jupyter notebook配置IRkernel见:

玩转Jupyter Notebook5-配置python|R|Julia|Stata


前提是R已经安装完毕

第一步

R中完成

options(repos=structure(c(CRAN="https://mirrors.tuna.tsinghua.edu.cn/CRAN/")))
install.packages('IRkernel',dependencies=TRUE)

报错:

tar: Failed to set default locale

解决:

system('defaults write org.R-project.R force.LANG en_US.UTF-8')

参考:https://stackmirror.com/page/3xysh3tfepl

第二步

R中完成

IRkernel::installspec(user = FALSE)

报错:
Error in IRkernel::installspec(user = FALSE) : 
  jupyter-client has to be installed but “jupyter kernelspec --version” exited with code 127.
In addition: Warning message:
In system2("jupyter", c("kernelspec", "--version"), FALSE, FALSE) :
  error in running command

解决:

R中完成

R.home()

/Library/Frameworks/R.framework/Resources/

添加bin/R

终端完成

>/Library/Frameworks/R.framework/Resources/bin/R

IRkernel::installspec(user = FALSE)#To install system-wide, set user to False in the installspec command:

报错:

[Errno 13] Permission denied: '/usr/local/share/jupyter'

Perhaps you want to install with `sudo` or `--user`?

解决:

直接root安装,完美解决

终端完成

>sudo /Library/Frameworks/R.framework/Resources/bin/R

R中完成

options(repos=structure(c(CRAN="https://mirrors.tuna.tsinghua.edu.cn/CRAN/")))#设置镜像源
install.packages('IRkernel',dependencies=TRUE)

试开URL’https://mirrors.tuna.tsinghua.edu.cn/CRAN/bin/macosx/contrib/4.0/IRkernel_1.1.1.tgz'

Content type 'application/octet-stream' length 221094 bytes (215 KB)

==================================================

downloaded 215 KB

下载的二进制程序包在/tmp/RtmpAqkmDv/downloaded_packages里


IRkernel::installspec(user = FALSE)#To install system-wide, set user to False in the installspec command:

[InstallKernelSpec] Installed kernelspec ir in /usr/local/share/jupyter/kernels/ir

退出R,jupyter notebook一下

完美解决。

jupyter notebook使用R实例

library(RColorBrewer) # 用分类调色板
par(mfrow = c(2, 1), mar = c(3, 2.5, 0.5, 0.1))
death <- t(VADeaths)[, 5:1]
barplot(death, col = brewer.pal(4, "Set1"))
barplot(death,
  col = brewer.pal(4, "Set1"), beside = TRUE,
  legend.text = TRUE
)

参考资料

https://stackoverflow.com/questions/44056164/jupyter-client-has-to-be-installed-but-jupyter-kernelspec-version-exited-wit/44108916

《现代统计图形》

猜你喜欢

转载自blog.csdn.net/qq_21478261/article/details/114359330
今日推荐