question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if youā€™re still stuck at the end, weā€™re happy to hop on a call to see how we can help out.

image.so on Apple Silicon can't load libpng16.16.dylib and libjpeg.9.dylib

See original GitHub issue

šŸ› Describe the bug

code:

import torchvision

UserWarning:

/Users/alanyoung/Documents/Codes/Kaggle/ClassifyLeaves/venv/lib/python3.9/site-packages/torchvision/io/image.py:11: UserWarning: Failed to load image Python extension: dlopen(/Users/alanyoung/Documents/Codes/Kaggle/ClassifyLeaves/venv/lib/python3.9/site-packages/torchvision/image.so, 0x0006): Library not loaded: @rpath/libpng16.16.dylib
  Referenced from: /Users/alanyoung/Documents/Codes/Kaggle/ClassifyLeaves/venv/lib/python3.9/site-packages/torchvision/image.so
  Reason: tried: '/Users/malfet/miniforge3/envs/py_39_torch-1.10.2/lib/libpng16.16.dylib' (no such file), '/Users/malfet/miniforge3/envs/py_39_torch-1.10.2/lib/libpng16.16.dylib' (no such file), '/Users/malfet/miniforge3/envs/py_39_torch-1.10.2/lib/libpng16.16.dylib' (no such file), '/Users/malfet/miniforge3/envs/py_39_torch-1.10.2/lib/libpng16.16.dylib' (no such file), '/opt/homebrew/Caskroom/miniforge/base/lib/libpng16.16.dylib' (no such file), '/opt/homebrew/Caskroom/miniforge/base/lib/libpng16.16.dylib' (no such file), '/opt/homebrew/Caskroom/miniforge/base/lib/python3.9/lib-dynload/../../libpng16.16.dylib' (no such file), '/opt/homebrew/Caskroom/miniforge/base/lib/libpng16.16.dylib' (no such file), '/opt/homebrew/Caskroom/miniforge/base/bin/../lib/libpng16.16.dylib' (no such file), '/usr/local/lib/libpng16.16.dylib' (no such file), '/usr/lib/libpng16.16.dylib' (no such file)
  warn(f"Failed to load image Python extension: {e}")

on M1 Max. In https://github.com/pytorch/vision/issues/5137#issuecomment-1023708994, it is said to be fixed but I donā€™t think so.

Therefore you canā€™t use torchvision.io.read_img().

import torchvision
img = torchvision.io.read_img('./1.jpg')
RuntimeError: No such operator image::read_file

In https://discuss.pytorch.org/t/failed-to-load-image-python-extension-could-not-find-module/140278/20, Andrade has the same problem.

Versions

Collecting environment informationā€¦ PyTorch version: 1.10.2 Is debug build: False CUDA used to build PyTorch: None ROCM used to build PyTorch: N/A

OS: macOS 12.1 (arm64) GCC version: Could not collect Clang version: 13.0.0 (clang-1300.0.29.30) CMake version: version 3.22.0 Libc version: N/A

Python version: 3.9.7 (default, Sep 16 2021, 23:53:23) [Clang 12.0.0 ] (64-bit runtime) Python platform: macOS-12.1-arm64-arm-64bit Is CUDA available: False CUDA runtime version: No CUDA GPU models and configuration: No CUDA Nvidia driver version: No CUDA cuDNN version: No CUDA HIP runtime version: N/A MIOpen runtime version: N/A

Versions of relevant libraries: [pip3] mypy-extensions==0.4.3 [pip3] numpy==1.22.2 [pip3] torch==1.10.2 [pip3] torchaudio==0.10.2 [pip3] torchvision==0.11.3 [conda] Could not collect

cc @seemethere @malfet

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:2
  • Comments:17 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
alanyoungCNcommented, Feb 14, 2022

@jdsgomes @malfet cc plz After thinking it for a long while, I find the key is libpng and libjpeg.

The image.so is indeed in torchvision/ even when torchvision=0.11.3, I only checked the torchvision/io/ folder before. So sorry for the previous title.

Then I take a deep look at the warning(same as the top):

/Users/alanyoung/Documents/Codes/Kaggle/ClassifyLeaves/venv/lib/python3.9/site-packages/torchvision/io/image.py:11: UserWarning: Failed to load image Python extension: dlopen(/Users/alanyoung/Documents/Codes/Kaggle/ClassifyLeaves/venv/lib/python3.9/site-packages/torchvision/image.so, 0x0006): Library not loaded: @rpath/libpng16.16.dylib
  Referenced from: /Users/alanyoung/Documents/Codes/Kaggle/ClassifyLeaves/venv/lib/python3.9/site-packages/torchvision/image.so
  Reason: tried: '/Users/malfet/miniforge3/envs/py_39_torch-1.10.2/lib/libpng16.16.dylib' (no such file), '/Users/malfet/miniforge3/envs/py_39_torch-1.10.2/lib/libpng16.16.dylib' (no such file), '/Users/malfet/miniforge3/envs/py_39_torch-1.10.2/lib/libpng16.16.dylib' (no such file), '/Users/malfet/miniforge3/envs/py_39_torch-1.10.2/lib/libpng16.16.dylib' (no such file), '/opt/homebrew/Caskroom/miniforge/base/lib/libpng16.16.dylib' (no such file), '/opt/homebrew/Caskroom/miniforge/base/lib/libpng16.16.dylib' (no such file), '/opt/homebrew/Caskroom/miniforge/base/lib/python3.9/lib-dynload/../../libpng16.16.dylib' (no such file), '/opt/homebrew/Caskroom/miniforge/base/lib/libpng16.16.dylib' (no such file), '/opt/homebrew/Caskroom/miniforge/base/bin/../lib/libpng16.16.dylib' (no such file), '/usr/local/lib/libpng16.16.dylib' (no such file), '/usr/lib/libpng16.16.dylib' (no such file)
  warn(f"Failed to load image Python extension: {e}")

I think the missing of @rpath/libpng16.16.dylib is the key. And the warning on my Mac even has a malfet name, which is so surprising.

Following the Reason: tried: ..... '/opt/homebrew/Caskroom/miniforge/base/lib/libpng16.16.dylib' ....., I try conda install libpng in my base conda env. Then I activate the torchvision env and import torchvision, the warning becomes Library not loaded: @rpath/libjpeg.9.dylib. This is very confusing.

What I think for now is that dlopen image.so needs both libpng and libjpeg and both of them canā€™t be found in ARM Mac, but Iā€™m not sure.

2reactions
fabiofumarolacommented, Jun 9, 2022

commands for mac

brew install libpng libjpeg
sudo ln -s /opt/homebrew/lib/* /usr/local/lib
Read more comments on GitHub >

github_iconTop Results From Across the Web

Resolving Library Loading Problems | Apple Developer Forums
When the dynamic linker fails to load a library it includes an explanation in the crash report. For example: Termination Reason: Namespace DYLD,Ā ......
Read more >
Compiling ART on OSX - #16 by sguyader - pixls.us
Hi all, I am trying to compile ART on OSX, but get an error while compiling. My compiler is: Apple clang version 12.0.0...
Read more >
dyld: Library not loaded: /usr/local/lib/libpng16.16.dylib with ...
I had a similar problem with ImageMagick obliterating /usr/local/bin/compare which I had going to diffmerge. ā€“ phpguru. May 9, 2014 at 16:15.
Read more >
Apache faults when using cURL with IMAP enabled
PHP does not log any errors, Apache log's a segmentation fault (see ... + 180 15 libcurl.4.dylib 0x0000000102302950 Curl_resolv + 296 16 ......
Read more >
MacOS version (#993) Ā· Issues Ā· Multimedia / Kdenlive Ā· GitLab
I haven't finished yet, but so far the first issue was license agreements. ... installing the Command-Line Tools from Apple (about 300MB),Ā ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found