简体   繁体   中英

Error attempting to open image with matplotlib.image

The following code does not work for me:

import matplotlib.image as mpimg
im = mpimg.imread('./dat/grey.jpg')

I have ensured that the grey.jpg exists, and I have PIL installed from here

Here's the error i'm getting:

    Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\ProgramData\Anaconda2\lib\site-packages\matplotlib\image.py", line 1278, in imread
    im = pilread(fname)
  File "C:\ProgramData\Anaconda2\lib\site-packages\matplotlib\image.py", line 1256, in pilread
    with Image.open(fname) as image:
  File "C:\ProgramData\Anaconda2\lib\site-packages\PIL\Image.py", line 512, in __getattr__
    raise AttributeError(name)
AttributeError: __exit__

any ideas on what's going on here? I'm thinking it could be a dependency issue. I have Python 2.7 32bit also

只需使用conda安装枕头即可:

conda install pillow

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM