在小牛中安装 RMySQL [英] Installing RMySQL in mavericks

查看:40
本文介绍了在小牛中安装 RMySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在安装 RMySQL 时遇到问题.我正在尝试通过以下方式从其源代码安装它:

I am having trouble installing RMySQL. I am trying to install it from its source in the following way:

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<MySQL-include-dir>"
      export PKG_LIBS="-L<MySQL-lib-dir> -lmysqlclient"

   Re-run the R INSTALL command:

      R CMD INSTALL RMySQL_<version>.tar.gz

2. Alternatively, you may pass the configure arguments
      --with-mysql-dir=<base-dir> (distribution directory)
   or
      --with-mysql-inc=<base-inc> (where MySQL header files reside)
      --with-mysql-lib=<base-lib> (where MySQL libraries reside)
   in the call to R INSTALL --configure-args='...' 

   R CMD INSTALL --configure-args='--with-mysql-dir=DIR' RMySQL_<version>.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

我可能会因为收到指示而为此大喊大叫,但行话已经超出了我的头脑,过去两个小时我一直在努力.有人可以帮忙吗?

I may get yelled out for this since I am getting instructions, but the lingo is over my head and I have been trying for the last two hours. Can anyone help?

推荐答案

我已经从 Mac 的源代码成功安装了 RMySQL 0.9-3:

I have successfully installed RMySQL 0.9-3 from source for Mac:

  • OS X 小牛队 10.9.4
  • 从 CRAN 和 rstudio.com 安装 R 3.1.0 和 RStudio 0.98.945
  • Xcode 5.1.1 和相应的命令行工具

有其他方法可以实现相同的目标,但我会尽量提供最友好的方式.以下是主要步骤:

There are alternatives to achieve the same goal, but I will try to provide the friendliest way. Here are the major steps:

1.确保您有可用的gcc".(看起来像)

转到应用程序 > 实用程序,打开终端,然后键入以下命令以验证命令行工具是否存在:($ 是终端中的命令提示符)

Go to Applications > Utilities, open Terminal, and type the following command to verify the command line tools exist: ($ is the command prompt in Terminal)

$ gcc
clang: error: no input files

如果您收到 -bash: gcc: command not found,您将需要在 独立版Xcode 方式.

If you receive -bash: gcc: command not found, you will need to install the command-line tools (gcc) in the standalone or Xcode way.

2.通过 Homebrew 安装 MySQL 客户端.

Homebrew 是一种包管理系统,可简化 Mac OS X 操作系统上的软件安装.

Homebrew is a package management system that simplifies the installation of software on the Mac OS X operating system.

首先,从终端安装 Homebrew:

First, Install Homebrew from Terminal:

$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

之后,输入brew"命令来检查是否安装了 Homebrew.然后通过 Homebrew 安装 MySQL:

After that, type "brew" command to check if Homebrew is installed. Then install MySQL via Homebrew:

$ brew install mysql

您应该看到 Downloading、Pouring、Caveats,最后是显示 MySQL 已安装的摘要.

You should see the Downloading, Pouring, Caveats, and finally the Summary showing that MySQL is installed.

您可以通过使用(默认)空密码以 root 身份连接到本地 MySQL 服务器来验证安装:

You can verify the installation by connecting to the local MySQL server as root with (default) empty password:

$ 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 服务器时遇到问题,但这超出了范围.

Use "exit" to exit the MySQL shell. You may have problems starting or connecting to your local MySQL server, but that's beyond the scope.

3.在 RStudio 中从源代码安装 RMySQL.

到目前为止,所有步骤都在终端中完成.虽然这一步也可以在终端中完成,但我将展示如何在 RStudio 中完成.来自您的错误消息:

So far, all the steps are done in Terminal. Although this step can also be done in Terminal, I will show how to do it in RStudio. From your error message:

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 无法找到要包含的头文件(include 事物)和要链接到的库(lib 事物).

This means that R can't find the header files (include things) to include and the libraries (lib things) to link to.

该指令告诉您设置 2 个环境变量 PKG_CPPFLAGSPKG_LIBS 以指示 includelib 的位置

The instruction tells you to set 2 environment variables PKG_CPPFLAGS and PKG_LIBS to indicate where the include and lib are.

假设您已经使用 Homebrew 中的默认路径安装了 MySQL.在 RStudio 中,您可以通过以下方式设置它们:(> 是 RStudio 中的命令提示符)

Assume you have installed MySQL with the default paths in Homebrew. Within RStudio, you can set them by: (> is the command prompt in 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 存储库或本地文件.

Finally, you should be able to install RMySQL from source correctly! Either from CRAN repo or the local file.

> install.packages("RMySQL", type = "source")

> install.packages("/path/to/package/RMySQL_0.9-3.tar.gz", repos = NULL, type = "source")

两者都会给你成功信息:

Both will give you the success message:

** 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 包:

As usual, load the RMySQL package by:

> library(RMySQL)
Loading required package: DBI
> 

<小时>

注意: R 中的 install.packages() 实际上在终端(Unix shell)环境中运行 R CMD INSTALL xxx.所以如果你更喜欢终端方式,你也可以通过终端中的export命令设置PKG_CPPFLAGSPKG_LIBS,然后运行R CMD INSTALL RMySQL_xxx.tar.gz 从您手动下载的源包安装.


Note: The install.packages() in R actually runs R CMD INSTALL xxx in the Terminal (Unix shell) environment. So if you prefer the Terminal way, you can also set PKG_CPPFLAGS and PKG_LIBS by the export command in Terminal, and run R CMD INSTALL RMySQL_xxx.tar.gz to install from the source package you have manually downloaded.

因此,以下方式也适用于终端中的第 3 步:

So the following way will also work in Terminal for Step 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

这篇关于在小牛中安装 RMySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆