问题描述
我一直在尝试安装一些软件包,例如RODBC,ROracle或RGtk2-用于发出嘎嘎声.如果有人可以帮助我解决此问题,以便我可以在带有标枪和3.1.1 R的Mac上使用这些应用程序,我将不胜感激.
我对于RODBC和RGtk2都遇到这种错误:
当我尝试使用type ='source'时,我可以下载或开始下载,但是随后出现这种错误消息...
在install.packages中的警告: 软件包"RODBC"的安装退出状态为非零
此答案将涵盖在OS X上(特别是在Mavericks及更高版本上)安装RODBC和ROracle.
这两个软件包现在都需要从源代码构建(编译).这意味着您首先需要下载XCode和相关的命令行工具",以便实际上拥有编译器.基本上每个版本的OS X/XCode的操作方式都已改变,但是如果您开始使用Google搜索,您可能最终会在此处登陆 a>.
一旦您准备好了……
RODBC
自OS X 10.9(小牛)以来,苹果公司就停止了将iODBC SQL头文件以及OS X上的R用户习惯于安装以构建R的命令行工具"来自源的软件包.
因此,如果您此时尝试从Mavericks上的源代码构建RODBC,则会出现类似以下错误:
要解决此问题,您需要下载最新版本的iODBC(www.iodbc.org),然后解压缩文件并设置标题和库搜索路径到放置解压缩包的位置.如果你不知道怎么做要设置搜索路径,您只需将头文件(sql.h和sqlext.h)放在/usr/include
目录中,和/usr/lib
目录中的libiodbc.a
文件.
那你应该就能做到
install.packages("RODBC",type = "source")
没有任何问题.大概这也可以与其他主要的开源ODBC项目unixODBC一起使用,但是我还没有尝试过.
我已经在El Capitan上对此进行了测试(以及另一种答案中的自制方法),并且两者仍然可以正常工作.
ROracle
这更复杂.但是,ROracle可以安装在OS X上(我已经通过El Capitan在Mountain Lion上进行了测试).由于ROracle依赖于Oracle Instant Client,因此没有可用的二进制文件.任何平台. 此处.有详细的安装说明.
对于OS X,我们(主要)需要遵循Linux的说明.
首先,下载相应的 Oracle Instant Client 以及SDK,如Linuz说明中所述.
Linux安装说明提到从RPM安装客户端,这会将所有内容放置在正确的位置".我无法弄清楚它是否也适用于OS X,所以我只是将客户端解压缩到我创建的目录中,然后将SDK放在/sdk
中的该目录中.
然后,Linux安装说明指导我们为libclntsh.so.11.1创建一个符号链接.自从这是OS X,实际上叫做libclntsh.dylib.11.1.所以我们需要cd到目录我们解压缩客户端,然后运行
ln -s libclntsh.dylib.11.1 libclntsh.dylib
然后在OS X上设置DYLD_LIBRARY_PATH
,而不是LD_LIBRARY_PATH
:
export DYLD_LIBRARY_PATH=/scratch/instantclient_11_2:$DYLD_LIBRARY_PATH
使用适合您计算机的任何路径.
我始终无法让ROracle使用OCI_LIB
环境变量进行编译.反而,我使用了--with-oci-lib
编译器标志选项:
R CMD INSTALL --configure-args='--with-oci-lib=/scratch/instantclient_11_2' ROracle_1.1-11.tar.gz
再次使用适当的路径和ROracle版本号.
如果要使用tnsnames.ora文件连接到Oracle数据库,则还需要设置TNS_ADMIN环境变量以指向该文件的位置.
最后一个陷阱:您可能会发现(就像我一样),只有启动R才能正常工作从命令行(即终端).具体来说,如果您启动RGui.app或从GUI,RStudio.app,然后尝试运行library(ROracle)
,您将收到一个错误说些什么
> library("ROracle")
Error in dyn.load(file, DLLpath = DLLpath, ...) :
unable to load shared object '/Library/Frameworks/R.framework/Versions/3.1/Resources/library/ROracle/libs/ROracle.so':
dlopen(/Library/Frameworks/R.framework/Versions/3.1/Resources/library/ROracle/libs/ROracle.so, 6): Library not loaded: /ade/b/3071542110/oracle/rdbms/lib/libclntsh.dylib.11.1
Referenced from: /Library/Frameworks/R.framework/Versions/3.1/Resources/library/ROracle/libs/ROracle.so
Reason: image not found
Error: package or namespace load failed for ‘ROracle’
即使Sys.getenv("DYLD_LIBRARY_PATH")
忠实地报告,也会发生这种情况正确的路径.
有一阵子,我破解了一个解决方案",在其中创建了一个外壳脚本,该外壳脚本启动了RStudio/RGui在启动时,只需要记住始终随后通过以下方式启动它们即可:
open -a R.app
open -a RStudio.app
问题显然与如何使用环境变量有关到OS X中GUI启动的应用程序.通常,我最终发现 StackOverflow 上的解决方案.编辑/etc/launchd.conf
文件解决了此问题,因此即使RStudio/RGui,ROracle现在也可以加载从Finder启动.尽管请注意此处,优胜美地不再支持/etc/launchd.conf
解决方案.该答案表明您现在需要设置一个启动plist文件,仅用于在启动时为launchctl
设置环境.
用于ROracle的El Capitan更新
我现在已经在El Capitan上的这个坩埚中进行了检查,它的工作如上所述,但前提是您首先禁用系统完整性保护!这样做相当快,并且可以通过Google轻松找到说明.
Ph.
I have been trying to install some packages such as RODBC, ROracle or RGtk2 - used for rattle. I would really appreciate it if someone could help me get around this problem so that I could use these applications on a Mac with mavericks and with 3.1.1 R
I get this sort of error for both RODBC and RGtk2:
When I try to use type='source', I can download or start to download but then I get this sort of error message...
Warning in install.packages : installation of package ‘RODBC’ had non-zero exit status
This answer will cover installing RODBC and ROracle on OS X, specifically on Mavericks and later.
Both packages now need to be built (compiled) from source. This means that the first thing you need is to download XCode and the associated "command line tools" so that you actually have a compiler. How you do this has changed with basically every version of OS X/XCode, but if you start Googling you will probably end up landing here.
Once you have that in place...
RODBC
Since OS X 10.9 (Mavericks) Apple stopped including the iODBC SQL header files along with the"command line tools" that R users on OS X are accustomed to installing in order to build Rpackages from source.
So if you try to build RODBC from source on Mavericks at this point you should get an error like:
To fix this, you need to download the latest version of iODBC (www.iodbc.org),and then unzip the file and set your header and library search pathsto the location where you put the unzipped package. If you don't know howto set your search paths, you could just put the header files (sql.h and sqlext.h) in the /usr/include
directory,and the libiodbc.a
file in the /usr/lib
directory.
Then you should be able to do
install.packages("RODBC",type = "source")
without any problems. Presumably this would work as well with the other major open source ODBC project, unixODBC, as well, but I have not tried that.
I have tested this (and the homebrew method in another answer) on El Capitan and both still work.
ROracle
This is more complicated. However, ROracle can be installed on OS X (I have tested this on Mountain Lion through El Capitan). Since ROracle relies on the Oracle Instant Client, there are no binaries available forany platform. There are detailed installation instructions for the package here.
For OS X, we need to (mostly) follow the Linux instructions.
First, download the appropriate Oracle Instant Client, as well as the SDK, as directed in the Linuz instructions.
The Linux install instructions mention installing the client from an RPM, which will place everything "in the right place". I wasn't able to figure out whether that even applied for OS X, so I simply unzipped the client in a directory I created and placed the SDK inside that directory in /sdk
.
The Linux install instructions then direct us to create a symbolic link for libclntsh.so.11.1. Sincethis is OS X, it's actually called libclntsh.dylib.11.1. So we need to cd to the directory wherewe unzipped the client and then run
ln -s libclntsh.dylib.11.1 libclntsh.dylib
On OS X, we then set the DYLD_LIBRARY_PATH
, not the LD_LIBRARY_PATH
:
export DYLD_LIBRARY_PATH=/scratch/instantclient_11_2:$DYLD_LIBRARY_PATH
using whatever path is correct for your machine.
I was never able to get ROracle to compile with an OCI_LIB
environment variable. Instead,I used the --with-oci-lib
compiler flag option:
R CMD INSTALL --configure-args='--with-oci-lib=/scratch/instantclient_11_2' ROracle_1.1-11.tar.gz
again using whatever path and ROracle version number is appropriate.
If you are connecting to an Oracle database using a tnsnames.ora file, you'll also need toset a TNS_ADMIN environment variable to point to the location of that file.
One last gotcha: you may find (as I did) that this will all work only if you launch Rfrom the command line (i.e. Terminal). Specifically, if you launch either RGui.app orRStudio.app from the GUI, and then try to run library(ROracle)
you will get an errorsaying something to the effect of
> library("ROracle")
Error in dyn.load(file, DLLpath = DLLpath, ...) :
unable to load shared object '/Library/Frameworks/R.framework/Versions/3.1/Resources/library/ROracle/libs/ROracle.so':
dlopen(/Library/Frameworks/R.framework/Versions/3.1/Resources/library/ROracle/libs/ROracle.so, 6): Library not loaded: /ade/b/3071542110/oracle/rdbms/lib/libclntsh.dylib.11.1
Referenced from: /Library/Frameworks/R.framework/Versions/3.1/Resources/library/ROracle/libs/ROracle.so
Reason: image not found
Error: package or namespace load failed for ‘ROracle’
This will happen even though Sys.getenv("DYLD_LIBRARY_PATH")
faithfully reportsthe correct path.
For a while, I hacked together a "solution" where I created a shell script that launchedRStudio/RGui upon startup, and just had to remember to always subsequently launch them via
open -a R.app
open -a RStudio.app
The problem apparently has to do with how environment variables are made availableto GUI launched applications in OS X. As is usually the case, I eventually found thesolution on StackOverflow. Editing the/etc/launchd.conf
file solved this problem, so ROracle now loads even when RStudio/RGuiare launched from the Finder. Though note here that the /etc/launchd.conf
solution is no longer supported in Yosemite. That answer suggests you now need to set up a start-up plist file just to set the environment for launchctl
on startup.
El Capitan Update for ROracle
I've now gone through the crucible on this one in El Capitan and it works as described above, but only if you disable System Integrity Protection first! Doing that is fairly quick, and instructions are easily found via Google.
Phew.
这篇关于在OS X Mavericks上安装RODBC/ROracle软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!