Mac M1上的Pytorch和Torchvision的问题 - Python / Conda
我试图在Mac M1上运行Pytorch和Torchvision。我按照以下说明成功安装了Pytorch并在Apple上本地运行 - “> https://betterprogramming.pub/how-to-install-pytorch-on-apple-m1-series-512b3ad9bc6
试图安装Torchvision时出现问题-I conda安装TorchVision(版本0.22)。但是,当我尝试导入它时,我会收到错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/gracecolverd/miniconda3/envs/pytorch_m2/lib/python3.8/site-packages/torchvision/__init__.py", line 2, in <module>
from torchvision import datasets
File "/Users/gracecolverd/miniconda3/envs/pytorch_m2/lib/python3.8/site-packages/torchvision/datasets/__init__.py", line 9, in <module>
from .fakedata import FakeData
File "/Users/gracecolverd/miniconda3/envs/pytorch_m2/lib/python3.8/site-packages/torchvision/datasets/fakedata.py", line 3, in <module>
from .. import transforms
File "/Users/gracecolverd/miniconda3/envs/pytorch_m2/lib/python3.8/site-packages/torchvision/transforms/__init__.py", line 1, in <module>
from .transforms import *
File "/Users/gracecolverd/miniconda3/envs/pytorch_m2/lib/python3.8/site-packages/torchvision/transforms/transforms.py", line 17, in <module>
from . import functional as F
File "/Users/gracecolverd/miniconda3/envs/pytorch_m2/lib/python3.8/site-packages/torchvision/transforms/functional.py", line 5, in <module>
from PIL import Image, ImageOps, ImageEnhance, PILLOW_VERSION
ImportError: cannot import name 'PILLOW_VERSION' from 'PIL' (/Users/gracecolverd/miniconda3/envs/pytorch_m2/lib/python3.8/site-packages/PIL/__init__.py)
它似乎是在尝试拉动不推荐的功能pillow_version,但是当我检查引用的pil init文件时,没有提及枕头_version
"""Pillow (Fork of the Python Imaging Library)
Pillow is the friendly PIL fork by Alex Clark and Contributors.
https://github.com/python-pillow/Pillow/
Pillow is forked from PIL 1.1.7.
PIL is the Python Imaging Library by Fredrik Lundh and Contributors.
Copyright (c) 1999 by Secret Labs AB.
Use PIL.__version__ for this Pillow version.
;-)
"""
from . import _version
# VERSION was removed in Pillow 6.0.0.
# PILLOW_VERSION was removed in Pillow 9.0.0.
# Use __version__ instead.
__version__ = _version.__version__
del _version
_plugins = [
"BlpImagePlugin",
"BmpImagePlugin",
"BufrStubImagePlugin",
"CurImagePlugin",
"DcxImagePlugin",
"DdsImagePlugin",
"EpsImagePlugin",
"FitsStubImagePlugin",
"FliImagePlugin",
"FpxImagePlugin",
"FtexImagePlugin",
"GbrImagePlugin",
"GifImagePlugin",
"GribStubImagePlugin",
"Hdf5StubImagePlugin",
"IcnsImagePlugin",
"IcoImagePlugin",
"ImImagePlugin",
"ImtImagePlugin",
"IptcImagePlugin",
"JpegImagePlugin",
"Jpeg2KImagePlugin",
"McIdasImagePlugin",
"MicImagePlugin",
"MpegImagePlugin",
"MpoImagePlugin",
"MspImagePlugin",
"PalmImagePlugin",
"PcdImagePlugin",
"PcxImagePlugin",
"PdfImagePlugin",
"PixarImagePlugin",
"PngImagePlugin",
"PpmImagePlugin",
"PsdImagePlugin",
"SgiImagePlugin",
"SpiderImagePlugin",
"SunImagePlugin",
"TgaImagePlugin",
"TiffImagePlugin",
"WebPImagePlugin",
"WmfImagePlugin",
"XbmImagePlugin",
"XpmImagePlugin",
"XVThumbImagePlugin",
]
class UnidentifiedImageError(OSError):
"""
Raised in :py:meth:`PIL.Image.open` if an image cannot be opened and identified.
"""
pass
ive ive检查了上面的文件夹以查看是否存在是枕头 Init ,但Havnt发现了任何东西。很想解决这个问题,所以我不必永远使用Colab!谢谢
Im trying to run Pytorch and Torchvision on Mac M1. I follow these instructions successfully install pytorch and run it natively on apple - https://betterprogramming.pub/how-to-install-pytorch-on-apple-m1-series-512b3ad9bc6
Issues comes when trying to install Torchvision - I conda install torchvision (version 0.22). But when I try to import it I get the error :
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/gracecolverd/miniconda3/envs/pytorch_m2/lib/python3.8/site-packages/torchvision/__init__.py", line 2, in <module>
from torchvision import datasets
File "/Users/gracecolverd/miniconda3/envs/pytorch_m2/lib/python3.8/site-packages/torchvision/datasets/__init__.py", line 9, in <module>
from .fakedata import FakeData
File "/Users/gracecolverd/miniconda3/envs/pytorch_m2/lib/python3.8/site-packages/torchvision/datasets/fakedata.py", line 3, in <module>
from .. import transforms
File "/Users/gracecolverd/miniconda3/envs/pytorch_m2/lib/python3.8/site-packages/torchvision/transforms/__init__.py", line 1, in <module>
from .transforms import *
File "/Users/gracecolverd/miniconda3/envs/pytorch_m2/lib/python3.8/site-packages/torchvision/transforms/transforms.py", line 17, in <module>
from . import functional as F
File "/Users/gracecolverd/miniconda3/envs/pytorch_m2/lib/python3.8/site-packages/torchvision/transforms/functional.py", line 5, in <module>
from PIL import Image, ImageOps, ImageEnhance, PILLOW_VERSION
ImportError: cannot import name 'PILLOW_VERSION' from 'PIL' (/Users/gracecolverd/miniconda3/envs/pytorch_m2/lib/python3.8/site-packages/PIL/__init__.py)
It seems to be trying to pull a deprecated function PILLOW_VERSION, but when I check the PIL init file referenced, there is no mention of the PILLOW_VERSION
"""Pillow (Fork of the Python Imaging Library)
Pillow is the friendly PIL fork by Alex Clark and Contributors.
https://github.com/python-pillow/Pillow/
Pillow is forked from PIL 1.1.7.
PIL is the Python Imaging Library by Fredrik Lundh and Contributors.
Copyright (c) 1999 by Secret Labs AB.
Use PIL.__version__ for this Pillow version.
;-)
"""
from . import _version
# VERSION was removed in Pillow 6.0.0.
# PILLOW_VERSION was removed in Pillow 9.0.0.
# Use __version__ instead.
__version__ = _version.__version__
del _version
_plugins = [
"BlpImagePlugin",
"BmpImagePlugin",
"BufrStubImagePlugin",
"CurImagePlugin",
"DcxImagePlugin",
"DdsImagePlugin",
"EpsImagePlugin",
"FitsStubImagePlugin",
"FliImagePlugin",
"FpxImagePlugin",
"FtexImagePlugin",
"GbrImagePlugin",
"GifImagePlugin",
"GribStubImagePlugin",
"Hdf5StubImagePlugin",
"IcnsImagePlugin",
"IcoImagePlugin",
"ImImagePlugin",
"ImtImagePlugin",
"IptcImagePlugin",
"JpegImagePlugin",
"Jpeg2KImagePlugin",
"McIdasImagePlugin",
"MicImagePlugin",
"MpegImagePlugin",
"MpoImagePlugin",
"MspImagePlugin",
"PalmImagePlugin",
"PcdImagePlugin",
"PcxImagePlugin",
"PdfImagePlugin",
"PixarImagePlugin",
"PngImagePlugin",
"PpmImagePlugin",
"PsdImagePlugin",
"SgiImagePlugin",
"SpiderImagePlugin",
"SunImagePlugin",
"TgaImagePlugin",
"TiffImagePlugin",
"WebPImagePlugin",
"WmfImagePlugin",
"XbmImagePlugin",
"XpmImagePlugin",
"XVThumbImagePlugin",
]
class UnidentifiedImageError(OSError):
"""
Raised in :py:meth:`PIL.Image.open` if an image cannot be opened and identified.
"""
pass
Ive checked the folder above to see if there is a PILLOW init but havnt found anything. Would love to fix this so I dont have to use colab forever! Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决了这个问题 - 问题是在torchvision function.py脚本中。
。我在/users/gracecol/miniconda3/envs/tv/lib/python3.10/site-packages/torchvision/transforms
for Pillow_version和functional.py i必须用
“ __”版本__“ __” __“
”Solved this - the issues was in the Torchvision functional.py script.
. I searched in /Users/gracecol/miniconda3/envs/tv/lib/python3.10/site-packages/torchvision/transforms
for PILLOW_VERSION and in functional.py I had to replace PILLOW_VERSION with
"__version__"