Google Colab has become one of the most popular tools for running Python code in the cloud. Whether you are training a machine learning model, analyzing data, or experimenting with computer vision, chances are you will need to insert and display images inside your notebook. Fortunately, Google Colab makes the process simple—once you understand the different methods available and when to use each one.
TLDR: You can insert images into Google Colab in multiple ways, including uploading from your computer, connecting to Google Drive, using URLs, or generating images with Python code. Each method serves a different purpose depending on your workflow. For quick experiments, direct uploads are easiest, but for larger projects, Google Drive integration is more efficient. With just a few lines of code, you can display images clearly inside your notebook outputs.
In this guide, you will learn step-by-step methods to insert images into Google Colab, along with practical examples and use cases. By the end, you will be confident in handling image files inside your notebooks—whether for visualization, documentation, or model training.
Why Insert Images into Google Colab?
Before diving into the “how,” it’s helpful to understand the “why.” Inserting images into Colab is useful for:
- Data exploration – viewing datasets in computer vision projects
- Visualization – showing results, graphs, or processed images
- Documentation – adding explanatory visuals to notebooks
- Testing AI models – feeding image inputs to deep learning systems
Because Google Colab runs in the cloud, you cannot directly access your computer’s local files without explicitly uploading them. This is why understanding file handling is essential.
Method 1: Upload an Image from Your Computer
The simplest way to insert an image into Colab is by uploading it directly from your local machine.
Step 1: Upload the Image File
Run the following code in a notebook cell:
from google.colab import files
uploaded = files.upload()
After running the cell, a file selection window will appear. Choose the image file from your computer. The file will then be uploaded to the notebook’s temporary environment.
Step 2: Display the Image
To display the uploaded image, use the Python Imaging Library (PIL) and Matplotlib:
from PIL import Image
import matplotlib.pyplot as plt
img = Image.open('your_image_name.jpg')
plt.imshow(img)
plt.axis('off')
This will render the image directly below the code cell.
Note: Files uploaded this way are temporary. If you restart the runtime, they will be deleted.
Method 2: Insert an Image from Google Drive
For long-term projects, storing images in Google Drive is a smarter solution. This method ensures your files remain available even if the Colab runtime resets.
Step 1: Mount Google Drive
from google.colab import drive
drive.mount('/content/drive')
You will be prompted to authorize access. Once completed, your Drive files will appear in the Colab file system.
Step 2: Locate and Open the Image
Suppose your image is stored in a folder named Images inside Drive. You can open it like this:
img = Image.open('/content/drive/MyDrive/Images/your_image_name.jpg')
plt.imshow(img)
plt.axis('off')
This method is ideal for:
- Large datasets
- Team collaborations
- Projects requiring persistent storage
Method 3: Insert an Image Using a URL
If your image is hosted online, you can load it directly using its URL. This is especially useful for testing or demonstration purposes.
import requests
from PIL import Image
from io import BytesIO
url = "https://example.com/image.jpg"
response = requests.get(url)
img = Image.open(BytesIO(response.content))
plt.imshow(img)
plt.axis('off')
This approach eliminates the need for uploads or Drive connections. However, it depends on the image being publicly accessible.
Method 4: Insert an Image into a Markdown Cell
Sometimes you don’t need to process an image—you simply want to display it for documentation purposes. In that case, you can insert it into a Markdown cell.
Use this format inside a Markdown cell:

Or if using a URL:

This is perfect for:
- Tutorial notebooks
- Project explanations
- Reports and presentations
Method 5: Display Images with OpenCV
If you are working in computer vision, chances are you are using OpenCV. Here is how you can display images using it:
import cv2
from google.colab.patches import cv2_imshow
img = cv2.imread('your_image_name.jpg')
cv2_imshow(img)
Note that in Google Colab, you must use cv2_imshow() instead of cv2.imshow(), because traditional OpenCV display functions do not work properly in notebook environments.
Common Issues and How to Fix Them
Even though inserting images in Colab is straightforward, beginners often encounter a few problems.
1. File Not Found Error
- Check spelling and capitalization.
- Ensure the file path is correct.
- Verify that the file has been uploaded.
2. Runtime Reset
- Uploaded files disappear after reset.
- Solution: Use Google Drive for persistence.
3. Image Not Displaying
- Confirm you used
plt.imshow()andplt.axis('off'). - With OpenCV, use
cv2_imshow().
Best Practices for Working with Images in Colab
To make your workflow smoother, consider these best practices:
- Organize files in folders inside Google Drive.
- Rename images clearly to avoid path confusion.
- Use relative paths consistently.
- Document image sources in Markdown cells.
- Resize large images before displaying to save memory.
For resizing an image:
img = img.resize((300, 300))
plt.imshow(img)
plt.axis('off')
When to Use Each Method
Here is a quick comparison to help you decide:
- Quick testing: Upload from computer
- Long projects: Google Drive
- Online resources: Image URL
- Computer vision tasks: OpenCV
- Documentation: Markdown embedding
Choosing the right approach will save you time and reduce frustration.
Final Thoughts
Inserting images into Google Colab may seem like a small task, but it plays a major role in data science, machine learning, and educational projects. Whether you are uploading a single picture for demonstration or loading thousands of training images from Google Drive, knowing the correct method ensures your workflow remains smooth and efficient.
The beauty of Colab lies in its flexibility. With just a few lines of Python, you can upload, display, manipulate, and analyze images directly in your browser—without installing complex software. Once you master these techniques, you will find it much easier to build visually rich notebooks that are both functional and professional.
Now that you know how to insert an image into Google Colab using multiple methods, you can confidently enhance your projects with visual elements that make your work clearer, more persuasive, and far more engaging.

