Home > Software design >  How to resolve 'libRblas.so: No such file or directory' during package installation?
How to resolve 'libRblas.so: No such file or directory' during package installation?

Time:07-15

When I try to install certain packages (imputeTS) that need libRblas.so which AFAIK refers to OpenBLAS I get an error that it was not found:

Error in dyn.load(file, DLLpath = DLLpath, ...) : 
  unable to load shared object '/home/jay/R/x86_64-pc-linux-gnu-library/4.2/fracdiff/libs/fracdiff.so':
  libRblas.so: cannot open shared object file: No such file or directory
Calls: <Anonymous> ... asNamespace -> loadNamespace -> library.dynam -> dyn.load
Execution halted

However, the sessionInfo() indicates, that R actually finds it.

> sessionInfo()
R version 4.2.1 (2022-06-23)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.20.so

I learned from this thread that "maybe ... another version of R [was built] and it sits in ... [the] $PATH before the packaged version", which is likely to be the case; my former R version 4.2.0 was a self-compiled one, and I removed it by downloading the source again and ./configure - make uninstall. This one is installed via sudo apt install r-base-core, though. Probably now there is a mess somewhere. Unfortunately the cited thread was solved differently, and I'm looking now for the respective conclusion.

Here is some more information:

whereis R gives

~$ whereis R
R: /usr/bin/R /usr/lib/R /usr/lib64/R /etc/R /usr/local/lib/R /usr/share/R /usr/share/man/man1/R.1.gz

From the respective files from the error message, using sudo find ~ -name '<file>', fracdiff.so was found, whereas libRblas.so wasn't.

~/R/x86_64-pc-linux-gnu-library/4.2/fracdiff/libs/fracdiff.so

I already tried,

~$ sudo apt install libopenblas-dev

but obviously it is installed.

libopenblas-dev is already the newest version (0.3.20 ds-1).

Following the suggestions of this, libRlapack.so and libRblas.so obviously don't exist on my system, and the other suggestion just gives:

~$ sudo update-alternatives --config libblas.so
update-alternatives: error: no alternatives for libblas.so

CodePudding user response:

There should never be a "requirement" for libRblas.so. In short, R allows you to build with the BLAS and LAPACK (subset of) sources it shipts, you then get this libRblas.so. Or you can use the system BLAS and LAPACK libraries, which the Debian (and hence Ubuntu) package I am responsible for has been doing for probably close to twenty years, and which allows you to switch BLAS installation (Atlas, OpenBLAS, MKL, back in the day also Goto, ...).

As a demonstration, I just launched a suitable Ubuntu 22.04 Docker container based on r2u as it combines having R pre-made (using my r-base-core package with the external BLAS linkage) as well as the (awesome !!) ability to take all of CRAN as Ubuntu binaries (see r2u for more). In short:

edd@rob:~$ docker run --rm -ti --security-opt seccomp=unconfined eddelbuettel/r2u:jammy                                                                                                                            
root@818091e49861:/# export PS1="root@r2u_docker:\w# "                                                                                                                                                             
root@r2u_docker:/# echo "192.168.1.114 dirk.eddelbuettel.com" >> /etc/hosts                                                                                                                                        
root@r2u_docker:/# install.r imputeTS              ## one command !!                                                                                                                                                                
Install system packages as root...                                                                                                                                                                                 
Reading package lists... Done                                                                                                                                                                                      
Building dependency tree... Done                                                                                                                                                                                   
Reading state information... Done                                                                                                                                                                                  
Ign https://dirk.eddelbuettel.com/cranapt jammy InRelease                                                                                                                                                         
Hit https://dirk.eddelbuettel.com/cranapt jammy Release                                                                                                                                                           
Hit http://archive.ubuntu.com/ubuntu jammy InRelease                                                                                                                                                              
Hit http://archive.ubuntu.com/ubuntu jammy-updates InRelease                                                                                                                                                      
Hit http://archive.ubuntu.com/ubuntu jammy-backports InRelease                                                                                                                                                    
Hit http://security.ubuntu.com/ubuntu jammy-security InRelease                                                                                                                                                     
Get:1 https://ppa.launchpadcontent.net/marutter/rrutter4.0/ubuntu jammy InRelease [17.5 kB]                                                                                                                        
Fetched 17.5 kB in 0s (0 B/s)                                                                                                                                                                                     
Reading package lists... Done                                                                                                                                                                                      
Building dependency tree... Done                                                                                                                                                                                   
Reading state information... Done                                                                                                                                                                                  
Get:1 https://dirk.eddelbuettel.com/cranapt jammy/main amd64 r-cran-bitops amd64 1.0-7-1.ca2204.1 [25.5 kB]                                                                                                       
Get:2 https://dirk.eddelbuettel.com/cranapt jammy/main amd64 r-cran-glue amd64 1.6.2-1.ca2204.1 [143 kB]                                                                                                           
[... cutting here to satisfy SO quote limit ...]
Setting up r-cran-forecast (8.16-1.ca2204.1) ...
Setting up r-cran-imputets (3.2-1.ca2204.1) ...
root@r2u_docker:/# 

after which we can indeed launch R and load it just fine:

root@r2u_docker:/# R

R version 4.2.1 (2022-06-23) -- "Funny-Looking Kid"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(imputeTS)
Registered S3 method overwritten by 'quantmod':
  method            from
  as.zoo.data.frame zoo 
> 

It uses external BLAS/LAPACK "by design":

root@r2u_docker:/# dpkg -l | grep -i "blas\|lapack" | cut -c-90
ii  libblas-dev:amd64            3.10.0-2ubuntu1                         amd64        Basi
ii  libblas3:amd64               3.10.0-2ubuntu1                         amd64        Basi
ii  liblapack-dev:amd64          3.10.0-2ubuntu1                         amd64        Libr
ii  liblapack3:amd64             3.10.0-2ubuntu1                         amd64        Libr
root@r2u_docker:/# 

So I think this may be self-imposed by a combination of you having maybe compiled R locally plus the imputeTS not dealing well with that (it should, it may be a bug). But I hope this also shows that this can be so much easier too.

If you have more detailed follow-up questions please come to the r-sig-debian list which is friendly, no-sensense and low-volume.

PS For completness, the container's sessionInfo() in a fresh session:

> sessionInfo()
R version 4.2.1 (2022-06-23)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.10.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods   base     

loaded via a namespace (and not attached):
[1] compiler_4.2.1 bspm_0.3.9    
> 

PPS A 'live' demo in one animated gif is in this tweet (tweeted as one cannot attach gifs over 2mb here).

CodePudding user response:

Some comments have put me on the right track and helped me to solve the problem—I will briefly summarize.

Since a dependencies issue was suspected, I installed the package from which the error message originated (fracdiff in this case) and tried again to install the target package. The error reoccurred, but came from a different package indicating cascading problems. Weirdly enough, I definitely knew the package was installed, so I felt my initial suspicion confirmed, that I might have made a mess with the libs folders when updating R as described in the OP.

Since I could assume that this would happen again and again, the conclusion was to uninstall R completely, and this time the packages as well, and then reinstall everything. Now I could install the target package among others without any problems.

Fortunately, this is quite easy on Linux. Also all packages can be reinstalled relatively unattended. The how-to's are spread out over several threads and sites, I'll put the strings together, adding the references.

Here is what I did in R and in Bash (you will need su/sudo):

  1. Store packages (in R) 1
tmp <- installed.packages()
installedpkgs <- as.vector(tmp[is.na(tmp[,"Priority"]), 1])
saveRDS(installedpkgs, 'installed_old.rds')
  1. Remove R completely 2
dpkg -l | grep ^ii | awk '$2 ~ /^r-/ { print $2 }' | sudo xargs apt-get remove --purge -y
  1. Remove all R packages 3

The locations might differ from yours.

R -e '.libPaths()'
rm -rf /home/jay/R/x86_64-pc-linux-gnu-library/4.2 /usr/local/lib/R/site-library /usr/lib/R/site-library /usr/lib/R/library
  1. Install R (here with apt) 4
apt install r-base-core
  1. Restore R packages 5

This runs for a while. Note that only packages that can be found in repositories are installed.

installedpkgs <- readRDS("installed_old.rds")
tmp <- installed.packages()
installedpkgs.new <- as.vector(tmp[is.na(tmp[,"Priority"]), 1])
missing <- setdiff(installedpkgs, installedpkgs.new)
install.packages(missing)
update.packages(ask=FALSE)
  • Related