>>> import torchvision Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/opt/anaconda3/envs/pytorch/lib/python3.9/site-packages/torchvision/__init__.py", line 7, in <module> from torchvision import datasets File "/opt/anaconda3/envs/pytorch/lib/python3.9/site-packages/torchvision/datasets/__init__.py", line 1, in <module> from .lsun import LSUN, LSUNClass File "/opt/anaconda3/envs/pytorch/lib/python3.9/site-packages/torchvision/datasets/lsun.py", line 2, in <module> from PIL import Image File "/opt/anaconda3/envs/pytorch/lib/python3.9/site-packages/PIL/Image.py", line 100, in <module> from . import _imaging as core ImportError: dlopen(/opt/anaconda3/envs/pytorch/lib/python3.9/site-packages/PIL/_imaging.cpython-39-darwin.so, 2): Library not loaded: @rpath/libjpeg.9.dylib Referenced from: /opt/anaconda3/envs/pytorch/lib/python3.9/site-packages/PIL/_imaging.cpython-39-darwin.so Reason: Incompatible library version: _imaging.cpython-39-darwin.so requires version 15.0.0 or later, but libjpeg.9.dylib provides version 12.0.0
时间: 2023-06-30 20:27:10 浏览: 528
Mac下anaconda中Spyder打开报错Traceback(most recent call last)…问题
5星 · 资源好评率100%
这个错误提示显示 PIL 库中的 _imaging.cpython-39-darwin.so 动态链接库依赖的 libjpeg.9.dylib 版本不兼容,需要版本号为 15.0.0 或更高版本。
解决方法:
1.卸载已安装的 Pillow 库,执行以下命令:
```
pip uninstall pillow
```
2. 安装 libjpeg-turbo,执行以下命令:
```
brew install libjpeg-turbo
```
3. 安装 Pillow 库,并指定使用 libjpeg-turbo 库,执行以下命令:
```
pip install --no-cache-dir -I pillow-SO_LATEST_VERSION --global-option="build_ext" --global-option="--disable-jpeg" --global-option="--enable-jpeg2000" --global-option="--enable-zlib" --global-option="--enable-turbojpeg"
```
其中,SO_LATEST_VERSION 是指最新版本的 Pillow 库的版本号。您可以在 PyPI 上查看最新版本的 Pillow 库的版本号。
4. 验证 Pillow 库是否安装成功,执行以下命令:
```
python -c "from PIL import Image; print(Image.core.jpeglib_version)"
```
如果输出的版本号为 libjpeg-turbo 的版本号,则说明安装成功。
阅读全文