Issues with Pytorch and Torchvision on MAC M1 - python / conda
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 &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;
  File &quot;/Users/gracecolverd/miniconda3/envs/pytorch_m2/lib/python3.8/site-packages/torchvision/__init__.py&quot;, line 2, in &lt;module&gt;
    from torchvision import datasets
  File &quot;/Users/gracecolverd/miniconda3/envs/pytorch_m2/lib/python3.8/site-packages/torchvision/datasets/__init__.py&quot;, line 9, in &lt;module&gt;
    from .fakedata import FakeData
  File &quot;/Users/gracecolverd/miniconda3/envs/pytorch_m2/lib/python3.8/site-packages/torchvision/datasets/fakedata.py&quot;, line 3, in &lt;module&gt;
    from .. import transforms
  File &quot;/Users/gracecolverd/miniconda3/envs/pytorch_m2/lib/python3.8/site-packages/torchvision/transforms/__init__.py&quot;, line 1, in &lt;module&gt;
    from .transforms import *
  File &quot;/Users/gracecolverd/miniconda3/envs/pytorch_m2/lib/python3.8/site-packages/torchvision/transforms/transforms.py&quot;, line 17, in &lt;module&gt;
    from . import functional as F
  File &quot;/Users/gracecolverd/miniconda3/envs/pytorch_m2/lib/python3.8/site-packages/torchvision/transforms/functional.py&quot;, line 5, in &lt;module&gt;
    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
&quot;&quot;&quot;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.

;-)
&quot;&quot;&quot;

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 = [
    &quot;BlpImagePlugin&quot;,
    &quot;BmpImagePlugin&quot;,
    &quot;BufrStubImagePlugin&quot;,
    &quot;CurImagePlugin&quot;,
    &quot;DcxImagePlugin&quot;,
    &quot;DdsImagePlugin&quot;,
    &quot;EpsImagePlugin&quot;,
    &quot;FitsStubImagePlugin&quot;,
    &quot;FliImagePlugin&quot;,
    &quot;FpxImagePlugin&quot;,
    &quot;FtexImagePlugin&quot;,
    &quot;GbrImagePlugin&quot;,
    &quot;GifImagePlugin&quot;,
    &quot;GribStubImagePlugin&quot;,
    &quot;Hdf5StubImagePlugin&quot;,
    &quot;IcnsImagePlugin&quot;,
    &quot;IcoImagePlugin&quot;,
    &quot;ImImagePlugin&quot;,
    &quot;ImtImagePlugin&quot;,
    &quot;IptcImagePlugin&quot;,
    &quot;JpegImagePlugin&quot;,
    &quot;Jpeg2KImagePlugin&quot;,
    &quot;McIdasImagePlugin&quot;,
    &quot;MicImagePlugin&quot;,
    &quot;MpegImagePlugin&quot;,
    &quot;MpoImagePlugin&quot;,
    &quot;MspImagePlugin&quot;,
    &quot;PalmImagePlugin&quot;,
    &quot;PcdImagePlugin&quot;,
    &quot;PcxImagePlugin&quot;,
    &quot;PdfImagePlugin&quot;,
    &quot;PixarImagePlugin&quot;,
    &quot;PngImagePlugin&quot;,
    &quot;PpmImagePlugin&quot;,
    &quot;PsdImagePlugin&quot;,
    &quot;SgiImagePlugin&quot;,
    &quot;SpiderImagePlugin&quot;,
    &quot;SunImagePlugin&quot;,
    &quot;TgaImagePlugin&quot;,
    &quot;TiffImagePlugin&quot;,
    &quot;WebPImagePlugin&quot;,
    &quot;WmfImagePlugin&quot;,
    &quot;XbmImagePlugin&quot;,
    &quot;XpmImagePlugin&quot;,
    &quot;XVThumbImagePlugin&quot;,
]


class UnidentifiedImageError(OSError):
    &quot;&quot;&quot;
    Raised in :py:meth:`PIL.Image.open` if an image cannot be opened and identified.
    &quot;&quot;&quot;

    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

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 &quot;__version__&quot;
