2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

MacOSでtorchvisionのimportエラー

Posted at

現象

torchvisionを読み込むと、libpngとか、libjpegのエラーが出る人向け。

import torchvision
/Users/<USER NAME>/.pyenv/versions/py38-test2/lib/python3.8/site-packages/torchvision/io/image.py:11: UserWarning: Failed to load image Python extension: dlopen(/Users/<USER NAME>/.pyenv/versions/3.8.12/envs/py38-test2/lib/python3.8/site-packages/torchvision/image.so, 0x0006): Library not loaded: @rpath/libpng16.16.dylib
  Referenced from: /Users/<USER NAME>/.pyenv/versions/3.8.12/envs/py38-test2/lib/python3.8/site-packages/torchvision/image.so
  Reason: tried: '/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}")

対策

/usr/local/lib/の下にシンボリックリンクを作成する。

sudo ln -s /opt/homebrew/Cellar/libpng/1.6.37/lib/libpng16.16.dylib /usr/local/lib/libpng16.16.dylib
sudo ln -s /opt/homebrew/Cellar/jpeg/9e/lib/libjpeg.9.dylib /usr/local/lib/libjpeg.9.dylib
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?