Answer the question
In order to leave comments, you need to log in
Why can't PIL find the open attribute of an Image object?
Hello. I am writing code to add pictures from VKontakte. Ran this code:
def create_icons_users(links_file):
label = Label(text='')
with open(links_file, 'r') as r: # открываем json файл с ссылками
links = json.load(r)
for link in links:
try:
response = requests.get(link, timeout=10)
except:
print('Ошибка!')
else:
pil_image = Image.open(BytesIO(response.content)) # тут ошибка
image = ImageTk.PhotoImage(pil_image)
label.config(image=image, text='') # добавляем картинку
label.image = image
label.pack()
File "path_to_file_code", line 64, in create_icons_users
<i>pil_image = Image.open(BytesIO(response.content))</i>
<b>AttributeError: type object 'Image' has no attribute 'open'</b>
Answer the question
In order to leave comments, you need to log in
The Image class from the PIL Image module does not really have an open method.
But there is an open function in the Image module of the PIL library.
from PIL import Image
img = Image.open("test.jpg")
img.save("test_good.jpg")
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question