Mac M1上的Pytorch和Torchvision的问题 - Python / Conda

发布于 2025-01-26 17:15:27 字数 3539 浏览 3 评论 0原文

我试图在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不疑不惑不回忆 2025-02-02 17:15:27

解决了这个问题 - 问题是在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.

  • In the error it mentioned which files were trying to pull this function
    . 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__"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文