首页 > 解决方案 > 无法在 jupyter 中为 r 内核安装 tidyverse 包

问题描述

我最近安装了Anaconda启用了 r 内核conda install -c r r-irkernel我参考了以下内容:https ://kyleake.medium.com/how-to-install-r-in-jupyter-with-irkernel-in-3-steps- 917519326e41

现在,jupyter notebook当我尝试安装 tidyverse软件包时,我收到以下错误jsonlite

Warning message:
"package 'tidyverse' was built under R version 3.6.3"
Error: package or namespace load failed for 'tidyverse' in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]):
 namespace 'jsonlite' 1.6 is already loaded, but >= 1.7.2 is required
Traceback:

1. library("tidyverse")
2. tryCatch({
 .     attr(package, "LibPath") <- which.lib.loc
 .     ns <- loadNamespace(package, lib.loc)
 .     env <- attachNamespace(ns, pos = pos, deps, exclude, include.only)
 . }, error = function(e) {
 .     P <- if (!is.null(cc <- conditionCall(e))) 
 .         paste(" in", deparse(cc)[1L])
 .     else ""
 .     msg <- gettextf("package or namespace load failed for %s%s:\n %s", 
 .         sQuote(package), P, conditionMessage(e))
 .     if (logical.return) 
 .         message(paste("Error:", msg), domain = NA)
 .     else stop(msg, call. = FALSE, domain = NA)
 . })
3. tryCatchList(expr, classes, parentenv, handlers)
4. tryCatchOne(expr, names, parentenv, handlers[[1L]])
5. value[[3L]](cond)
6. stop(msg, call. = FALSE, domain = NA)

似乎jsonlite' 1.6 is already loaded, but >= 1.7.2 is required是问题所在,所以当我尝试手动安装时jsonlite,我遇到了这个问题:

install.packages("jsonlite")


package 'jsonlite' successfully unpacked and MD5 sums checked
Warning message:
"cannot remove prior installation of package 'jsonlite'"Warning message in file.copy(savedcopy, lib, recursive = TRUE):
"problem copying C:\ProgramData\Anaconda3\Lib\R\library\00LOCK\jsonlite\libs\x64\jsonlite.dll to C:\ProgramData\Anaconda3\Lib\R\library\jsonlite\libs\x64\jsonlite.dll: Permission denied"Warning message:
"restored 'jsonlite'"

The downloaded binary packages are in
    C:\Users\viny\AppData\Local\Temp\RtmpADyCWE\downloaded_packages

那么我该如何安装tidyverse packagejupyter notebook

标签: rjupyter-notebooktidyversejupyter-irkernel

解决方案


不要混合conda installinstall.packages。仅install.packages在包不在 conda 上时使用。tidyverse 在 conda 上(请参阅 anaconda.org/r/r-tidyverse),所以你应该时不时remove.packages("tidyverse")conda install -c r r-tidyverse.

您可能也有兴趣了解提供更多 R 包的 conda-forge 频道。

如果您也在使用 Python,这也适用于混合使用 pip install 和 conda install - 这样做会以难以想象的方式破坏您的安装(请参阅在同一环境中使用 conda 和 pip install 是一个坏主意吗?)。这在很大程度上可以归因于 conda 使用其自己的机制来处理库/包路径,而这些路径与其他分发系统的交互并不好。


推荐阅读