Reputation: 1
I am a begginer programer in python and when i run this code
from PIL import Image
im = Image.open(r'C:\\images\\imagetest.png')
width, height = im.size
print(width, height)
im.show()
I get this error:
im = Image.open(r'C:\\images\\imagetest.png')
File "C:\Users\danie\AppData\Local\Programs\Python\Python38\lib\site-packages\PIL\Image.py", line 2878, in open
fp = builtins.open(filename, "rb")
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\\\images\\\\imagetest.png'
PS C:\Users\danie\vscode projects>
Upvotes: 0
Views: 1846
Reputation: 567
r strings don't need their backslashes escaped
Remove the r before the string declaration or remove the double backslashes
Upvotes: 3
Reputation: 11
As the error said, the path you gave is incorrect. this
im = Image.open(r'C:\\images\\imagetest.png')
have issues such as double "\" which is not the proper format. Sometimes you also have the give it the full path: Example of a path:
C:\Users\Hamza\Downloads\me.jpg
If you're not sure about the path copy it from here example path for an image
Upvotes: 0
Reputation: 38
The path of the image is not correct. You have to write it like that:
im = Image.open(r'C:\images\imagetest.png')
Upvotes: 0