我在安装RMySQL时遇到问题.我试图通过以下方式从源代码安装它:
install.packages("/path/to/package/RMySQL_0.9-3.tar.gz",repos = NULL,type="source")
然后我得到:
Installing package into ‘/Users/Library/R/3.1/library’ (as ‘lib’ is unspecified) * installing *source* package ‘RMySQL’ ... ** package ‘RMySQL’ successfully unpacked and MD5 sums checked checking for gcc... gcc checking for C compiler default output file name... a.out checking whether the C compiler works... yes checking whether we are cross compiling... no checking for suffix of executables... checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ANSI C... none needed checking how to run the C preprocessor... gcc -E checking for compress in -lz... yes checking for getopt_long in -lc... yes checking for mysql_init in -lmysqlclient... no checking for egrep... grep -E checking for ANSI C header files... rm: conftest.dSYM: is a directory rm: conftest.dSYM: is a directory yes checking for sys/types.h... yes checking for sys/stat.h... yes checking for stdlib.h... yes checking for string.h... yes checking for memory.h... yes checking for strings.h... yes checking for inttypes.h... yes checking for stdint.h... yes checking for unistd.h... yes checking mysql.h usability... no checking mysql.h presence... no checking for mysql.h... no checking for mysql_init in -lmysqlclient... no checking for mysql_init in -lmysqlclient... no checking for mysql_init in -lmysqlclient... no checking for mysql_init in -lmysqlclient... no checking for mysql_init in -lmysqlclient... no checking for mysql_init in -lmysqlclient... no checking for mysql_init in -lmysqlclient... no checking /usr/local/include/mysql/mysql.h usability... no checking /usr/local/include/mysql/mysql.h presence... no checking for /usr/local/include/mysql/mysql.h... no checking /usr/include/mysql/mysql.h usability... no checking /usr/include/mysql/mysql.h presence... no checking for /usr/include/mysql/mysql.h... no checking /usr/local/mysql/include/mysql/mysql.h usability... no checking /usr/local/mysql/include/mysql/mysql.h presence... no checking for /usr/local/mysql/include/mysql/mysql.h... no checking /opt/include/mysql/mysql.h usability... no checking /opt/include/mysql/mysql.h presence... no checking for /opt/include/mysql/mysql.h... no checking /include/mysql/mysql.h usability... no checking /include/mysql/mysql.h presence... no checking for /include/mysql/mysql.h... no Configuration error: could not find the MySQL installation include and/or library directories. Manually specify the location of the MySQL libraries and the header files and re-run R CMD INSTALL. INSTRUCTIONS: 1. Define and export the 2 shell variables PKG_CPPFLAGS and PKG_LIBS to include the directory for header files (*.h) and libraries, for example (using Bourne shell syntax): export PKG_CPPFLAGS="-I" export PKG_LIBS="-L -lmysqlclient" Re-run the R INSTALL command: R CMD INSTALL RMySQL_ .tar.gz 2. Alternatively, you may pass the configure arguments --with-mysql-dir= (distribution directory) or --with-mysql-inc= (where MySQL header files reside) --with-mysql-lib= (where MySQL libraries reside) in the call to R INSTALL --configure-args='...' R CMD INSTALL --configure-args='--with-mysql-dir=DIR' RMySQL_ .tar.gz ERROR: configuration failed for package ‘RMySQL’ * removing ‘/Library/R/3.1/library/RMySQL’ Warning in install.packages : installation of package ‘/path/to/package/RMySQL_0.9-3.tar.gz’ had non-zero exit status
因为我正在接受指示,所以我可能因此而大声喊叫,但是这个术语已经过去了,而且我在过去的两个小时里一直在努力.有人可以帮忙吗?
我已经从Mac的源代码成功安装了RMySQL 0.9-3:
OS X Mavericks 10.9.4
从CRAN和rstudio.com安装R 3.1.0和RStudio 0.98.945
Xcode 5.1.1和相应的命令行工具
有其他方法可以实现相同的目标,但我会尝试提供最友好的方式.以下是主要步骤:
1.确保你有"gcc"可用.(看起来像你这样做)
转到应用程序>实用程序,打开终端,然后键入以下命令以验证命令行工具是否存在:($是终端中的命令提示符)
$ gcc clang: error: no input files
如果收到-bash: gcc: command not found
,则需要以独立或Xcode方式安装命令行工具(gcc).
2.通过Homebrew安装MySQL客户端.
Homebrew是一种软件包管理系统,可简化Mac OS X操作系统上的软件安装.
首先,从终端安装Homebrew:
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
之后,键入"brew"命令以检查是否安装了Homebrew.然后通过Homebrew安装MySQL:
$ brew install mysql
您应该看到下载,浇注,警告,最后是显示MySQL已安装的摘要.
您可以通过以(默认)空密码连接到本地MySQL服务器来验证安装:
$ mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.6.19 Homebrew ... (skipped) ... mysql>
使用"exit"退出MySQL shell.您可能在启动或连接到本地MySQL服务器时遇到问题,但这超出了范围.
3.在RStudio中从源安装RMySQL.
到目前为止,所有步骤都在终端完成.虽然这一步也可以在终端中完成,但我将展示如何在RStudio中完成.从您的错误消息:
Configuration error: could not find the MySQL installation include and/or library directories. Manually specify the location of the MySQL libraries and the header files and re-run R CMD INSTALL. INSTRUCTIONS: 1. Define and export the 2 shell variables PKG_CPPFLAGS and PKG_LIBS to include the directory for header files (*.h) and libraries, for example (using Bourne shell syntax): export PKG_CPPFLAGS="-I<MySQL-include-dir>" export PKG_LIBS="-L<MySQL-lib-dir> -lmysqlclient" Re-run the R INSTALL command: R CMD INSTALL RMySQL_<version>.tar.gz
这意味着R无法找到要包含的头文件(包括东西)和要链接的库(lib东西).
该指令告诉您设置2个环境变量PKG_CPPFLAGS和PKG_LIBS以指示include和lib的位置.
假设您已使用Homebrew中的默认路径安装MySQL.在RStudio中,您可以通过以下方式设置它们:(>是RStudio中的命令提示符)
### These are the KEY COMMANDS in this turotial ### > Sys.setenv(PKG_CPPFLAGS = "-I/usr/local/include/mysql") > Sys.setenv(PKG_LIBS = "-L/usr/local/lib -lmysqlclient")
最后,您应该能够正确地从源安装RMySQL!来自CRAN repo或本地文件.
> install.packages("RMySQL", type = "source")
要么
> install.packages("/path/to/package/RMySQL_0.9-3.tar.gz", repos = NULL, type = "source")
两者都会给你成功的信息:
** libs clang -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include/mysql/ -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -fPIC -Wall -mtune=core2 -g -O2 -c RS-DBI.c -o RS-DBI.o clang -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG -I/usr/local/include/mysql/ -I/usr/local/include -I/usr/local/include/freetype2 -I/opt/X11/include -fPIC -Wall -mtune=core2 -g -O2 -c RS-MySQL.c -o RS-MySQL.o clang -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/usr/local/lib -o RMySQL.so RS-DBI.o RS-MySQL.o -L/usr/local/lib/ -lmysqlclient -lz -F/Library/Frameworks/R.framework/.. -framework R -Wl,-framework -Wl,CoreFoundation installing to /Library/Frameworks/R.framework/Versions/3.1/Resources/library/RMySQL/libs ** R ** inst ** preparing package for lazy loading Creating a generic function for ‘format’ from package ‘base’ in package ‘RMySQL’ Creating a generic function for ‘print’ from package ‘base’ in package ‘RMySQL’ ** help *** installing help indices ** building package indices ** testing if installed package can be loaded * DONE (RMySQL)
像往常一样,通过以下方式加载RMySQL包:
> library(RMySQL) Loading required package: DBI >
注:在install.packages()
R中实际运行R CMD INSTALL xxx
在终端(Unix外壳)环境.因此,如果您更喜欢终端方式,还可以通过终端中的导出命令设置PKG_CPPFLAGS和PKG_LIBS,并R CMD INSTALL RMySQL_xxx.tar.gz
从您手动下载的源包运行安装.
因此,以下方法也适用于第3步的终端:
$ export PKG_CPPFLAGS="-I/usr/local/include/mysql" $ export PKG_LIBS="-L/usr/local/lib -lmysqlclient" $ R CMD INSTALL RMySQL_0.9-3.tar.gz