简体   繁体   English

错误“.onLoad 在 'tcltk' 的 loadNamespace() 中失败”

[英]Error ".onLoad failed in loadNamespace() for 'tcltk'"

I have a general question about how to effectively load any kind of external package into R.我有一个关于如何有效地将任何类型的外部 package 加载到 R 的一般问题。 I have found that many sources detailing this information are simply insufficient, but I will leave out mentioning those respective URLs.我发现许多详细说明此信息的来源根本不够,但我将省略提及这些相应的 URL。 I have successfully loaded external packages into R before, but I am having difficulties loading the fgui package.我之前已经成功地将外部包加载到 R 中,但是我在加载fgui package 时遇到了困难。

In my specific case, I cannot load the library fgui into R Studio.在我的具体情况下,我无法将库fgui加载到 R Studio 中。 First I download directly from CRAN with the command:首先,我使用以下命令直接从 CRAN 下载:

install.packages("fgui", lib="~/Documents/R_dir")

This works fine for me.这对我来说很好。 My working directory is set to ~/Documents/R_dir我的工作目录设置为 ~/Documents/R_dir

The next command I use is:我使用的下一个命令是:

library("fgui", lib.loc="~/Documents/R_dir")

The error I get is:我得到的错误是:

Error : .onLoad failed in loadNamespace() for 'tcltk', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/Library/Frameworks/R.framework/Versions/3.1/Resources/library/tcltk/libs/tcltk.so':
dlopen(/Library/Frameworks/R.framework/Versions/3.1/Resources/library/tcltk/libs/tcltk.so, 10): Library not loaded: /opt/X11/lib/libX11.6.dylib
Referenced from: /Library/Frameworks/R.framework/Versions/3.1/Resources/library/tcltk/libs/tcltk.so
Reason: image not found
Error: package or namespace load failed for ‘fgui’

I have examined the thread " Error when trying to load library(ggplot2) in R " but it did not answer my question.我已经检查了线程“ 尝试在 R 中加载库(ggplot2)时出错”,但它没有回答我的问题。

Please help me with any suggestions to get the package fgui to work properly in R Studio and feel free to address the more general issue of effectively loading external packages into R.请帮助我提供任何建议以使 package fgui在 R Studio 中正常工作,并随时解决将外部包有效加载到 ZE1E1D3D40573127E9EE0480CAF1283D6 的更普遍问题

tcltk is not a typical package. tcltk不是典型的软件包。 It's probably already installed on your system and it cannot be installed using the usual install.packages procedure because it is not on CRAN (just like the base packages that come with R, like stats , etc.). 它可能已经安装在您的系统上,并且不能使用常规的install.packages过程安装,因为它不在CRAN上(就像R附带的基本软件包,如stats一样)。 Also, tcltk2 is not the same as tcltk ; 另外, tcltk2tcltk that is a package that expands upon (and depends on) the functionality of tcltk . 这是一个扩展(并取决于) tcltk功能的tcltk

So, start with this: 因此,从此开始:

> capabilities("tcltk")
tcltk 
 TRUE

If that comes back FALSE it means that your R was not built with tcltk support. 如果返回FALSE则意味着您的R并非受tcltk支持。 You don't say what OS you're using, so it's a little bit difficult to help you. 您没有说您正在使用什么操作系统,因此为您提供帮助有点困难。

That said, if you're on Linux , you need to rebuild R with tcltk support . 也就是说,如果您使用的是Linux ,则需要使用tcltk support重建R。 This should be relatively straightforward. 这应该是相对简单的。 Basically, make sure Tcl and tk are available on your system in a standard location (something like sudo apt-get install tcl8.5-dev tk8.5-dev ) and then rebuild R per usual procedures. 基本上,确保Tcl和tk在系统上的标准位置可用(诸如sudo apt-get install tcl8.5-dev tk8.5-dev ),然后按照常规过程重建R。

If you're on Mac OS , you're encountering the same error that John Fox describes here in relation to Rcmdr . 如果您使用的是Mac OS ,则您会遇到John Fox在此描述的与Rcmdr有关的相同错误。 In short, it's probably one of two things: 简而言之,这可能是两件事之一:

  1. A file permission issue related to the directory where you have Tcl installed. 与您已安装Tcl的目录有关的文件许可权问题。 To quote Fox: "You can verify the source of this problem by issuing the following command at the R command prompt: 引用Fox的话:“您可以通过在R命令提示符处发出以下命令来验证此问题的根源:

     system("ls -ld /usr/local /usr/local/lib /usr/local/lib/libtcl*") # ls: /usr/local/lib: Permission denied # ls: /usr/local/lib/libtcl*: Permission denied # drwx------ 8 root wheel 272 Sep 24 10:21 /usr/local 

If the output of the system command looks like the above, you should go to Terminal and do the following: sudo chmod -R a+rX /usr/local and enter your password to change directory permissions. 如果system命令的输出如上所示,则应转到Terminal并执行以下操作: sudo chmod -R a+rX /usr/local并输入密码以更改目录权限。

  1. You have an out-dated version of X-Windows. 您有一个过时的X-Windows版本。 Try running Mac OS Software Update. 尝试运行Mac OS软件更新。

It may also be solvable by creating a symbolic link as described in this answer . 如本答案所述,通过创建符号链接也可以解决该问题

This should never come up on Windows , unless you built R from source without tcl/tk support. 除非您是在没有tcl / tk支持的情况下从源代码构建R的,否则这在Windows上永远不会出现。

The official installation instructions for R say: R官方安装说明说:

Note: the use of X11 (including tcltk) requires XQuartz to be installed since it is no longer part of OS X. Always re-install XQuartz when upgrading your OS X to a new major version. 注意:使用X11(包括tcltk)需要安装XQuartz ,因为它不再是OS X的一部分。在将OS X升级到新的主要版本时,请始终重新安装XQuartz。

So: Simply (re)install XQuartz if you want to use the tcltk package in R. 因此:如果要在R中使用tcltk软件包,只需(重新)安装XQuartz。

  1. delete the X11 file on location : /opt 删除以下位置的X11文件:/ opt
  2. delete the X11 on application unitiltiy 删除应用程序统一的X11
  3. reinstall X11 again 再次重新安装X11

Problem solved... 问题解决了...

For Mac-OS users: 对于Mac-OS用户:

I struggled with this problem recently and found that R-3.1.2 has a bug, which assumes that otool is installed when it is not. 最近我在这个问题上苦苦挣扎,发现R-3.1.2有一个错误,该错误假定安装otool时已安装。

R-3.0.0 (and later) ships with Tck/Tk 8.6.0, so you shouldn't need to install that. R-3.0.0(及更高版本)随Tck / Tk 8.6.0一起提供,因此您不需要安装它。

Simply upgrading to a more recent version of R (3.4.2) fixed the problem for me. 只需升级到R(3.4.2)的更新版本,便可以解决我的问题。

I had the same issue and went down a rabbit hole before discovering a simple fix. 我遇到了同样的问题,在发现一个简单的解决方法之前就陷入了困境。 If you install R from bianry it will include tcltk by default. 如果从bianry安装R,则默认情况下它将包括tcltk。 Just run the installer with the default installation. 只需使用默认安装运行安装程序。 You can get the .dmg here: https://cran.r-project.org/bin/macosx/ 您可以在此处获取.dmg: https//cran.r-project.org/bin/macosx/

On Arch Linux, tk is a separate package from tcl and both need to be installed: 在Arch Linux上, tk是与tcl分开的软件包,并且都需要安装:

sudo pacman -S tcl tk

This is given that the output from capabilities("tcltk") with R is TRUE (which means your R is compiled with tcltk support as noted previously in the answers here, this should be the case if you installed it from the arch repos). 假定具有R的capabilities("tcltk")的输出为TRUE (这意味着您的R是使用tcltk支持编译的,如先前在此处的答案所述,如果是从arch存储库安装的,则应为这种情况)。

Easiest answer for Mac users: Mac 用户最简单的答案:

1- Install tcl-tk using brew: 1- 使用 brew 安装 tcl-tk:

brew install tcl-tk

2- Run the following code: 2-运行以下代码:

ln -s /usr/local/Cellar/tcl-tk/$version/lib/libtcl8.6.dylib /usr/local/lib/libtcl8.6.dylib
ln -s /usr/local/Cellar/tcl-tk/$version/lib/libtk8.6.dylib /usr/local/lib/libtk8.6.dylib

Problem solved!问题解决了!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Rcmdr错误:.onLoad在'tcltk'的loadNamespace()中失败 - Rcmdr Error : .onLoad failed in loadNamespace() for 'tcltk' 错误:.onLoad在'tcltk'的loadNamespace()中失败,详细信息: - Error: .onLoad failed in loadNamespace() for 'tcltk', details: 错误:“ geoR”的程序包或名称空间加载失败:.tcltk的loadNamespace()在.onLoad中失败 - Error: package or namespace load failed for ‘geoR’: .onLoad failed in loadNamespace() for 'tcltk' 错误:'tcltk' 的 loadNamespace() 中的 .onLoad 失败,详细信息:调用:fun(libname, pkgname) - Error : .onLoad failed in loadNamespace() for 'tcltk', details:call: fun(libname, pkgname) R - 错误:'rJava' 的 loadNamespace() 中的 .onLoad 失败 - R - Error : .onLoad failed in loadNamespace() for 'rJava' 'utils' 的 loadNamespace() 中的 onLoad 失败,详细信息 - onLoad failed in loadNamespace() for 'utils', details 错误:.onLoad在'rJava'的loadNamespace()中失败,详细信息在安装软件包时 - Error : .onLoad failed in loadNamespace() for 'rJava', details while installing a package 安装包时,.onLoad在'rJava'的loadNamespace()中失败 - .onLoad failed in loadNamespace() for 'rJava' when installing a package 错误:'rJava' 的 loadNamespace() 中的 .onLoad 失败,详细信息:调用:inDL(x, as.logical(local), as.logical(now), ...) - Error : .onLoad failed in loadNamespace() for 'rJava', details: call: inDL(x, as.logical(local), as.logical(now), …) 错误:loadNamespace 中“tidyverse”的包或命名空间加载失败 - Error: package or namespace load failed for ‘tidyverse’ in loadNamespace
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM