Failed to install png package

I am on Apple M1 Big Sur. I installed R and libpng using homebrew.

When I try to install the png package, the error is:

/opt/homebrew/opt/llvm/bin/clang -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/opt/homebrew/Cellar/r/4.1.1/lib/R/lib -L/opt/homebrew/opt/llvm/lib -L/opt/homebrew/Cellar/gettext/0.21/lib -L/opt/homebrew/Cellar/libpng/1.6.37/lib -o png.so read.o write.o -L/opt/homebrew/Cellar/r/4.1.1/lib/R/lib -lR -lintl -Wl,-framework -Wl,CoreFoundation
/bin/sh: libpng-config: command not found

Error: package or namespace load failed for ‘png’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/opt/homebrew/lib/R/4.1/site-library/00LOCK-png/00new/png/libs/png.so':
  dlopen(/opt/homebrew/lib/R/4.1/site-library/00LOCK-png/00new/png/libs/png.so, 6): Symbol not found: _png_create_info_struct
  Referenced from: /opt/homebrew/lib/R/4.1/site-library/00LOCK-png/00new/png/libs/png.so
  Expected in: flat namespace
 in /opt/homebrew/lib/R/4.1/site-library/00LOCK-png/00new/png/libs/png.so
Error: loading failed
Execution halted

Please help, thanks!

Hi MaggieWang,

I seem to have the same problem. To expand on the error, here are some clues:

  • I got a similar error for a different package when I mistakenly installed gfortran for Intel based Macs. As soon as I reinstalled it for ARM based Macs, the problem was resolved.
  • I installed gfortran manually, because I previously installed it using homebrew, but that approach is apparently problematic.
  • This seems to give some background on the flat namespace error.

I haven't been able to solve the png error. I previously installed libpng through homebrew, and now tried to install it manually, but can't find a binary for it. It seems to support ARM based Macs.

Hope this helps someone on here to identify the problem, and possibly a solution!

Hi MaggieWang,

A colleague resolved the issue today. He tried two things, the second worked for me, but the first might be good to start with.

  1. In Terminal, install libpng using homebrew: brew install libpng. If you're not using homebrew, you can get it here. See whether this fixes the problem, if not, end all R sessions (if you hadn't before), install it again and try again.
  2. I already had a brew installation of libpng. But one R package (farver) was locked for some reason. Apparently, R locks packages during installation and unlocks them afterwards. But if something goes wrong, the package may remain locked. Removing the locked package resolved the problem. To find the location of all packages run R.home() in R. The library folder in that folder hosts all installed packages. Within that folder, I removed the 00LOCK-farver folder using rm -rf 00LOCK-farver (in Terminal). Make sure to close all R sessions before you do so, otherwise you might interrupt other processes.

Hope one of these options works for you as well.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.