from PIL import Image
import random
img = Image.open("pratik.JPG")
print(img.size)
print(img.format)
img.show()
我运行了这段代码,但它没有显示图片,而是给了我随机包的importerror。它说from random import Random as _Random
。
Traceback (most recent call last):
File "C:/Users/lenovo/PycharmProjects/Python/Pillow.py", line 8, in <module>
img.show()
File "C:\Users\lenovo\AppData\Roaming\Python\Python35\site-packages\PIL\Image.py", line 1775, in show
_show(self, title=title, command=command)
File "C:\Users\lenovo\AppData\Roaming\Python\Python35\site-packages\PIL\Image.py", line 2520, in _show
_showxv(image, **options)
File "C:\Users\lenovo\AppData\Roaming\Python\Python35\site-packages\PIL\Image.py", line 2525, in _showxv
ImageShow.show(image, title, **options)
File "C:\Users\lenovo\AppData\Roaming\Python\Python35\site-packages\PIL\ImageShow.py", line 51, in show
if viewer.show(image, title=title, **options):
File "C:\Users\lenovo\AppData\Roaming\Python\Python35\site-packages\PIL\ImageShow.py", line 75, in show
return self.show_image(image, **options)
File "C:\Users\lenovo\AppData\Roaming\Python\Python35\site-packages\PIL\ImageShow.py", line 94, in show_image
return self.show_file(self.save_image(image), **options)
File "C:\Users\lenovo\AppData\Roaming\Python\Python35\site-packages\PIL\ImageShow.py", line 90, in save_image
return image._dump(format=self.get_format(image))
File "C:\Users\lenovo\AppData\Roaming\Python\Python35\site-packages\PIL\Image.py", line 568, in _dump
import tempfile
File "C:\Users\lenovo\AppData\Local\Programs\Python\Python35\lib\tempfile.py", line 45, in <module>
from random import Random as _Random
ImportError: cannot import name 'Random'