Installing nloptr on Linux

谁说我不能喝 提交于 2019-12-02 19:08:23

When you say [t]his command in turn looks for the following file online you only get half the story. Together with Jelmer, the maintainer of the actual nloptr package, I modified the package to do the following:

  • look for an install libnlopt library, and, if found, use it
  • if not found fall back to the old behaviour and download the library

So you could simply install nlopt via

 sudo apt-get install libnlopt-dev

(or the equivalent sudo dpkg -i /media/.... pointing to the file from a USB drive etc pp) and then reinstall the nloptr package. It will just work. On my machine:

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:~$ 

Note how it compiled only two files from the actual R packages having found the nlopt installation.

I had exactly the same problem, on a production machine without direct Internet access, with Red Hat Enterprise Linux Server release 6.6 (Santiago). The fixups proposed above did not work: when installing the nlopt library on the system, the subsequent attempt to install nloptr fail with the "nlopt_set_maxtime" error. I tried to fiddle with compilation options for nlopt, to no avail. I even reproduced the problem on a Ubuntu machine with Internet connection: I uninstalled nloptr, installed nlopt on the system and then the nloptr installation failed.

At last I solved the issue taking the following steps:

  1. Un-install nlopt from the operating system (make sure that it is thoroughly removed).
  2. Manually download nlopt-2.4.2.tar.gz and copy it to /tmp/
  3. Manually download nloptr_1.0.4.tar.gz to a work directory and unpack it; this creates the directory "nloptr/".
  4. Edit "nloptr/configure", comment out the row

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

    and insert a new row:

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

  5. Install with "R CMD INSTALL nloptr".

Ole Høst

I had a similar problem on Ubuntu. In addition to installing nlopt-dev as Dirk answered, I also had to install pkg-config:

sudo apt-get install pkg-config

Hope this helps.

If you are on CentOS (and have internet access, but the nlopt server is not reachable), you can install nlopt first using

yum install nlopt nlopt-devel

Then you can install nloptr normally.

I had the same issue setting up nloptr on my RHEL 7.2 instance. For those using RHEL you can do the following: Download & install the following RPMS in the same order:

Please note that these RPMs may need additional dependencies to be installed based on your system configuration.

Post this you can install nloptr directly using the install.packages utility or download source from CRAN and install from source as suggested in earlier responses.

Hope this helps!

Kiran

if you are using AWS Linux the below should help

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

I think I have the same problem as you and I am using CentOS 6.5 Remove nlopt and install nloptr with install.packages() in R, a nlopt will be installed automatically.

I removed installed nlopt with the following command in the unzipped nlopt folder.

make uninstall 

If you had tried to use epel repository in CentOS and had installed nlopt with yum, try:

yum remove nlopt

After removing existed nlopt, I am able to install nloptr with

install.packages("nloptr")
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!