Skip to content
Related Articles

Related Articles

Improve Article
How to open an image from the URL in PIL?
  • Last Updated : 26 Mar, 2021

In this article, we will learn How to open an image from the URL using the PIL module in python. For the opening of the image from a URL in Python, we need two Packages urllib and Pillow(PIL).


  • Install the required libraries and then import them. To install use the following commands:
pip install pillow
  • Copy the URL of any image.
  • Write URL with file name in urllib.request.urlretrieve() method.
  • Use method to open image.
  • At last show the image using method.

Sample Code: 

import urllib.request

from PIL import Image

urllib.request.urlretrieve(‘Image url’, “file_name”)

img =“file_name”)



# importing modules
import urllib.request
from PIL import Image
img ="gfg.png")


 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up
Recommended Articles
Page :