0
from PIL import Image
import random

img = Image.open("pratik.JPG")

print(img.size)
print(img.format)

img.show()

I ran this code but it does not show the image, rather it gives me an importerror for the random package. It says 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'
halfer
  • 19,824
  • 17
  • 99
  • 186
Pratik Sondkar
  • 1
  • 1
  • 1
  • 3

0 Answers0