conda创建`R`或`R相关包`的虚拟环境并被jupyter识别

conda创建`R`或`R相关包`的虚拟环境并被jupyter识别

整体要求:

  1. 创建的python新环境需要配置ipykernel使其被jupyter识别
  2. 创建的R新环境需要配置ipykernelIRkernel使其被jupyter识别。IRkernel通过ipykernel完成配置,因此需要先装ipykernel,再装IRkernel

在新环境中安装RR相关包并被识别

以安装R为例

#  创建名为 R 的虚拟环境
$ conda create R
# 激活虚拟环境 R
$ conda activate R

# 在虚拟环境R中安装 R
$ conda install r-base=4.1.3
# 在虚拟环境R中安装 ipykernel
$ conda install -c conda-forge ipykernel
# 在虚拟环境R中安装 IRkernel
$ conda install -c conda-forge r-irkernel

# 在虚拟环境R中启动R
$ R

启动R后界面如下:

R version 4.0.5 (2021-03-31) -- "Shake and Throw"
Copyright (C) 2021 The R Foundation for Statistical Computing
Platform: x86_64-conda-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

[Previously saved workspace restored]

# 配置 IRkernel ,'name'用于命名核心名称,'displayname'用于命名jupyter中展示的核心名称
> IRkernel::installspec(name = "ir_R", displayname = 'R')

从jupyter中删除R kernel

以删除上述ir_Rkernel为例

# 回到初始环境(在该环境中运行的 jupyter-lab)
$ conda activate base

# 列出jupyter中所有的kernel
$ jupyter kernelspec list

# 删除kernel 'ir_R'
$ jupyter kernelspec remove ir_R

参考:
jupyter 识别 python 虚拟环境
jupyter 识别 R 虚拟环境
Jupyter 删除不用的kernel

Tips:
When using R with conda, some people recommend to install all R packages via conda and not let R install packages. This is because R looks for header files (i.e. dev libraries) in canonical locations where these files are typically located when installed by the OS package manager. For more on R with conda, see this answer on the RStudio forum.

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值