r - Jupyter 笔记本:loadNamespace 中的“caret”的包或命名空间加载失败
问题描述
我原本打算问以下问题,但我自己想通了,并决定发布以下问题和答案,以防它可能对遇到同样问题的人有所帮助:
我目前正在使用 R 在 Jupyter Notebook 中开展一个项目。
一切正常,直到我尝试加载插入符号library(caret)
并收到以下错误消息:
Error: package or namespace load failed for 'caret' in loadNamespace(j <- i[[1L]], c(lib.loc, > > .libPaths()), versionCheck = vI[[j]]):
there is no package called 'codetools'
Traceback:
1. library(caret)
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)
我已经尝试在 RStudio 中卸载并重新安装caret
,但这也无济于事。更令人气愤的是,在我的 RStudio 中一切正常,只是 Jypyter notebook 无法找到caret
.
这是我的会话信息仅供参考:
R version 3.6.0 (2019-04-26)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 15063)
Matrix products: default
locale:
[1] LC_COLLATE=English_United Kingdom.1252
[2] LC_CTYPE=English_United Kingdom.1252
[3] LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] ggplot2_3.3.0 lattice_0.20-38
loaded via a namespace (and not attached):
[1] Rcpp_1.0.3 pillar_1.4.2 compiler_3.6.0 plyr_1.8.4
[5] base64enc_0.1-3 iterators_1.0.12 tools_3.6.0 digest_0.6.22
[9] uuid_0.1-2 jsonlite_1.6 evaluate_0.14 tibble_2.1.3
[13] gtable_0.3.0 nlme_3.1-142 pkgconfig_2.0.3 rlang_0.4.5
[17] foreach_1.4.7 IRdisplay_0.7.0 IRkernel_1.0.2 repr_1.0.1
[21] withr_2.1.2 dplyr_0.8.3 grid_3.6.0 tidyselect_0.2.5
[25] glue_1.3.1 R6_2.4.1 pbdZMQ_0.3-3 purrr_0.3.3
[29] magrittr_1.5 scales_1.0.0 codetools_0.2-16 htmltools_0.4.0
[33] assertthat_0.2.1 timeDate_3043.102 colorspace_1.4-1 munsell_0.5.0
[37] crayon_1.3.4
```
解决方案
我通过在 Jupyter Notebook 中卸载解决了这个caret
问题remove.packages("caret")
。我还检查了该软件包是否不再安装在 RStudio 中。
然后,我在 Jupyter notebook 中重新安装caret
了。install.packages("caret", dependencies = TRUE)
我认为导致问题的原因是 Jupyter 没有安装caret
的依赖包。从问题中的第一条错误消息来看,这是codetools
. 每次我安装错误中命名的包时,它都会想出另一个包来安装。这让我觉得——当然——它没有安装任何依赖项。
caret
现在在 Jupyter Notebook 中工作。
推荐阅读
- ionic-framework - 离子 - 分配失败 - JavaScript 堆内存不足
- python - TypeError:'list'和'str' Python 3.6.2的实例之间不支持'<'
- kaa - 将 linux 服务器时区更改为 UTC 后,KAA 服务器未启动(PSQLException:FATAL:参数“TimeZone”的值无效:“UTC”)
- c++ - 在 MacOS 上使用 Bazel 构建时无法调试 C++ 代码
- java - 如何创建自定义进度条
- regex - 尝试将单词组合与两者之间的变化进行匹配
- powershell - RemoteApp 和桌面连接无法通过命令更新
- ruby-on-rails - 如何找出rails(包括gems)加载了哪些语言环境文件?
- decision-tree - XGBoost 修剪步骤在做什么?
- php - Strava API 在 webhook 注册时返回“格式错误的请求”