1

I'm trying to install the package "png" on RStudio but I get the following error, I run on Ubuntu 16.04:

     Error: package or namespace load failed for ‘png’ in dyn.load(file,
     DLLpath = DLLpath, ...):

     unable to load shared object '/home/doma/R/x86_64-pc-linux-gnu  
     library/3.4/png/libs/png.so':

     libpng16.so.16: cannot open shared object file: No such file or directory

     Error: loading failed
     Execution halted

I have installed Anaconda so I was wondering if it could be the problem, since the file libpng16.so.16 is actually installed in anaconda's libraries. Thank you!

2
  • It shouldn't, the R package calls the library from its own directory. Try to reinstall, use remove.packages() to remove the package.
    – thc
    Nov 22, 2017 at 0:42
  • I uninstalled Anaconda and it worked just fine!
    – django
    Nov 22, 2017 at 8:52

2 Answers 2

4

You must install this ubuntu package before installing png in R. Try the following:

Installing directly using apt-get.

sudo apt-get install libpng16-16

If this doesn't work, please install manually.

wget https://cfhcable.dl.sourceforge.net/project/libpng/libpng16/1.6.34/libpng-1.6.34.tar.xz
tar xf libpng-1.6.34.tar.xz
cd libpng-1.6.34/
./configure
sudo make check
sudo make install

Finally, install R package in R terminal.

> install.packages('png')
1
  • First, I had to update my environment variable (export LD_LIBRARY_PATH="/usr/local/lib:$LD_LIBRARY_PATH") before starting R. Then I could run install.packages("png")
    – Todd
    Jun 2, 2020 at 20:25
1

On CentOS7, system-wide libpng is 15, while anaconda has 16. During install.packages('png'), called is gcc with flag -L/<path_to_anaconda>/anaconda/lib. I temporarily removed anaconda path from PATH variable, then the gcc command of install.packages('png') becomes without the flag, and install.packages('png') installed successfully.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.