Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error when using Matplotlib.image in Python

Okay, so I just started this tutorial using Anaconda in PyCharm. I imported the correct libraries, but when I try to upload my image using this code:

img = mpimg.imread('FileName.png')

I get this error message:

Traceback (most recent call last): File "<input>", line 1, in <module> File ".../matplotlib/image.py", line 1323, in imread with open(fname, 'rb') as fd: IOError: [Errno 2] No such file or directory: 'FileName.png'

I tried putting in the file location like this:

img=mpimg.imread('FilePath/FileName.png')

But I got the same error. I want to follow the tutorial exactly so I'm not sure why this isn't working! Any help is appreciated!

like image 311
KatrinaMay14 Avatar asked Oct 23 '25 03:10

KatrinaMay14


1 Answers

Make sure that there is that file in the folder... Try this command to list the files in that folder just to make sure that python atleast recognizes or reads the files.

import os
print (os.listdir('your path'))
like image 66
hashcode55 Avatar answered Oct 25 '25 01:10

hashcode55