问题 How can I open an image in PIL, then print the md5 hash of the image without saving it to a file and reading the file? 回答1: You could save the image to a io.BytesIO() , and take the md5 hash of its value: import hashlib import Image import io img = Image.open(FILENAME) m = hashlib.md5() with io.BytesIO() as memf: img.save(memf, 'PNG') data = memf.getvalue() m.update(data) print(m.hexdigest()) This will compute the same md5 hash as if you saved the Image to a file, then read the file into a