在Linux上安装nloptr

时间:2015-04-18 11:44:20

标签: r centos nlopt

我正在尝试在没有互联网连接的CentOS Linux机器上安装R包 nloptr ,如下所示:

install.packages("/home/ravi/nloptr_1.0.4.tar.gz", repos = NULL, type="source")

此命令依次在线查找以下文件

http://ab-initio.mit.edu/nlopt/nlopt-2.4.2.tar.gz

然而,由于没有与机器的互联网连接,因此失败。

我尝试了以下stackoverflow帖子中的建议:

trouble with Installing nloptr by locally on Ubuntu

我更改了configure和configure.ac文件中的URL,如下所示:

NLOPT_URL="file:///home//ravi//${NLOPT_TGZ}"

但是,当我尝试再次安装软件包时出现以下错误:

> install.packages("/home/ravi/nloptr_1.0.4.tar.gz", repos = NULL, type="source")
* installing *source* package 'nloptr' ...
files 'configure', 'configure.ac' have the wrong MD5 checksums
ERROR: 'configure' exists but is not executable -- see the 'R Installation and Administration Manual'
* removing '/opt/vertica/R/library/nloptr'
Warning message:
In install.packages("/home/ravi/nloptr_1.0.4.tar.gz",  :
  installation of package '/home/ravi/nloptr_1.0.4.tar.gz' had non-zero exit status

有人可以指导我如何在本地安装此R包吗?

更新1

根据Dirk关于首先安装nlopt的建议,我按照以下页面中的说明进行操作:

http://ab-initio.mit.edu/wiki/index.php/NLopt_Installation

我按如下方式安装了nlopt:

./configure --enable-shared
make
make install
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:/usr/local/lib

当我尝试在R中重新安装nloptr时,它不再查找nlopt链接,但会引发以下错误:

Error in dyn.load(file, DLLpath = DLLpath, ...) :
  unable to load shared object '/opt/vertica/R/library/nloptr/libs/nloptr.so':
  /opt/vertica/R/library/nloptr/libs/nloptr.so: undefined symbol:   nlopt_set_maxtime
Error: loading failed
Execution halted
ERROR: loading failed
* removing '/opt/vertica/R/library/nloptr'
Warning message:
In install.packages("/home/ravi/nloptr_1.0.4.tar.gz",  :
  installation of package '/home/ravi/nloptr_1.0.4.tar.gz' had non-zero exit     status

更新2

根据Dirk的建议,我查看了ldconfig命令并使用了以下参考:

http://codeyarns.com/2014/01/14/how-to-add-library-directory-to-ldconfig-cache/

我编辑了/etc/ld.so.conf文件,添加了包含共享库的目录/ usr / local / lib并运行了ldconfig命令。这增加了相关的共享库,如下所示:

libnlopt.so.0 (libc6,x86-64) => /usr/local/lib/libnlopt.so.0
libnlopt.so (libc6,x86-64) => /usr/local/lib/libnlopt.so

但是,当我尝试重新安装nloptr包时,我仍然会收到相同的共享对象错误。

有人可以指导我共享库错误吗?

8 个答案:

答案 0 :(得分:30)

当你说 [t]他的命令依次在线查找以下文件时你只能得到一半的故事。与实际nloptr包的维护者Jelmer一起,我修改了包以执行以下操作:

  • 寻找安装libnlopt库,如果找到,请使用它
  • 如果找不到,则回退到旧行为并下载库

所以你可以通过

简单地安装nlopt
 sudo apt-get install libnlopt-dev

(或等效的sudo dpkg -i /media/....指向a的文件 USB驱动器等pp)然后重新安装nloptr包。它会起作用。在我的机器上:

edd@max:~$ install.r nloptr         ## install.r is in littler
trying URL 'http://cran.rstudio.com/src/contrib/nloptr_1.0.4.tar.gz'
Content type 'application/x-gzip' length 353942 bytes (345 KB)
==================================================
downloaded 345 KB

* installing *source* package ‘nloptr’ ...
** package ‘nloptr’ successfully unpacked and MD5 sums checked
checking for g++... g++
checking whether the C++ compiler works... yes
checking for C++ compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking how to run the C++ preprocessor... g++ -E
checking whether we are using the GNU C++ compiler... (cached) yes
checking whether g++ accepts -g... (cached) yes
checking for pkg-config... yes
configure: Now testing for NLopt header file.
[...]
checking for nlopt.h... yes
configure: Suitable NLopt library found.
configure: creating ./config.status
config.status: creating src/Makevars
** libs
g++ -I/usr/share/R/include -DNDEBUG      -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -g  -O3 -Wall -pipe -Wno-unused -pedantic  -c dummy.cpp -o dummy.o
gcc -I/usr/share/R/include -DNDEBUG      -fpic  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -g  -O3 -Wall -pipe -pedantic -std=gnu99 -c nloptr.c -o nloptr.o
g++ -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o nloptr.so dummy.o nloptr.o -lnlopt -lm -L/usr/lib/R/lib -lR
installing to /usr/local/lib/R/site-library/nloptr/libs
** R
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
* DONE (nloptr)

The downloaded source packages are in
        ‘/tmp/downloaded_packages’
edd@max:~$ 

请注意它是如何仅从已找到nlopt安装的实际R包中编译两个文件的。

答案 1 :(得分:13)

我在红帽企业Linux服务器版本6.6(圣地亚哥)上没有直接上网的生产机器上遇到了完全相同的问题。上面提出的修正工作不起作用:在系统上安装nlopt库时,随后尝试安装nloptr会失败并使用" nlopt_set_maxtime"错误。我试图摆弄nlopt的编译选项,但无济于事。我甚至在具有Internet连接的Ubuntu机器上重现了这个问题:我卸载了nloptr,在系统上安装了nlopt,然后nloptr安装失败了。

最后我通过以下步骤解决了问题:

  1. 从操作系统中卸载nlopt(确保将其彻底删除)。
  2. 手动下载nlopt-2.4.2.tar.gz并将其复制到/ tmp /
  3. 手动将nloptr_1.0.4.tar.gz下载到工作目录并解压缩;这将创建目录" nloptr /"。
  4. 编辑" nloptr / configure",注释掉行

    $(" $ {R_HOME} / bin / Rscript" --vanilla -e " download.file(url =' $ {NLOPT_URL}',destfile =' $ {NLOPT_TGZ}')")

    并插入一个新行:

    $(" $ {R_HOME} / bin / Rscript" --vanilla -e " file.copy(from =' /tmp/nlopt-2.4.2.tar.gz' ;, to =' $ {NLOPT_TGZ}')")

  5. 安装" R CMD INSTALL nloptr"。

答案 2 :(得分:12)

我在Ubuntu上遇到过类似的问题。除了安装nlopt-dev为Dirk answered之外,我还必须安装pkg-config:

sudo apt-get install pkg-config

希望这有帮助。

答案 3 :(得分:6)

如果您使用的是CentOS(并且可以访问互联网,但无法访问nlopt服务器),则可以先使用

安装nlopt
yum install nlopt nlopt-devel

然后您可以正常安装nloptr

答案 4 :(得分:3)

我在RHEL 7.2实例上设置nloptr时遇到了同样的问题。对于使用RHEL的用户,您可以执行以下操作: 下载&按相同顺序安装以下RPMS:

请注意,根据您的系统配置,这些RPM可能需要安装其他依赖项。

发布此内容后,您可以使用install.packages实用程序直接安装nloptr,或者从CRAN下载源代码,并按照之前的响应中的建议从源代码安装。

希望这有帮助!

基兰

答案 5 :(得分:0)

如果您使用的是AWS Linux,则以下内容应该有所帮助

yum --enablerepo=epel install NLopt-devel -y

答案 6 :(得分:0)

我刚刚通过以下两个步骤在我的服务器上解决了这个问题:

  1. 安装libnlopt-devnlopt
sudo apt-get install libnlopt-dev
pip install nlopt
  1. 使用 sudo R 启动 R 并输入:
withr::with_makevars(c(PKG_LIBS='-lnlopt'),install.packages('nloptr'),assignment='+=')

答案 7 :(得分:-2)

我想我和你有同样的问题,而且我使用的是CentOS 6.5 删除nlopt并在R中安装带有install.packages()的nloptr,将自动安装nlopt。

我在解压缩的nlopt文件夹中使用以下命令删除了已安装的nlopt。

make uninstall 

如果您曾尝试在CentOS中使用epel存储库并且已经使用yum安装了nlopt,请尝试:

yum remove nlopt

删除已存在的nlopt后,我可以使用

安装nloptr
install.packages("nloptr")