Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
328 views
in Technique[技术] by (71.8m points)

r - Installing RMySQL in mavericks

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")

Then I get:

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

  • OS X Mavericks 10.9.4
  • R 3.1.0 and RStudio 0.98.945 installed from CRAN and rstudio.com
  • Xcode 5.1.1 and the corresponding command-line tools

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

1. Make sure you have "gcc" available. (looks like you do)

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

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. Install MySQL client via Homebrew.

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

First, Install Homebrew from Terminal:

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

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

$ brew install mysql

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

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> 

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. Install RMySQL from source in 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

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

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

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")

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

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

or

> 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)

As usual, load the RMySQL package by:

> library(RMySQL)
Loading required package: DBI
> 

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.

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...