Remove Image Background Using Python | rembg Tutorial (Windows & Linux) | Beginner Friendly

Published: 03 January 2026
on channel: Ali Husnain
45
2

In this lecture, you will learn how to remove image backgrounds automatically using Python and AI with the powerful rembg library.

This tutorial works on both Windows and Linux (Kali / Ubuntu) and is designed for beginners who want to build real AI-based tools using Python.

We will create a clean Conda environment, install required dependencies, and write a simple yet powerful Python script to remove backgrounds from images.

🔹 What You Will Learn

What is rembg and how it works

Python version compatibility (important)

Conda environment setup (Windows & Linux)

Installing dependencies correctly

Writing background removal code

Running the script without errors

Common mistakes and solutions

🔹 Step 1: Create Conda Environment (Windows & Linux)

Works the same on Windows CMD / PowerShell and Linux Terminal

conda create -n rembg python=3.11 -y
conda activate rembg
pip install rembg pillow onnxruntime

🔹 Step 2: Python Code (Same for Windows & Linux)
from rembg import remove
from PIL import Image

input_path = "/home/hackerali/Desktop/Background Remove/d.jpg"
output_path = "/home/hackerali/Desktop/Background Remove/bg.png"

with Image.open(input_path) as img:
output = remove(img)
output.save(output_path)

print("Background removed successfully!")

🔹 Windows Users: Important Path Change

If you are on Windows, update file paths like this:

input_path = r"C:\Users\Ali\Desktop\Background Remove\d.jpg"
output_path = r"C:\Users\Ali\Desktop\Background Remove\bg.png"


✔ Use raw string (r"")
✔ Use backslashes (\)

🔹 Requirements

Windows / Linux / Kali Linux

Python 3.10 or 3.11 (recommended)

Anaconda or Miniconda

Basic Python knowledge

🔹 Why Use rembg?

AI-based background removal

Works offline

No API key needed

Fast and accurate

Perfect for automation and projects

🔹 Use Cases

YouTube thumbnails

Profile pictures

AI tools

Image preprocessing

Freelancing projects

🔔 Support the Channel

If this lecture helped you:

Like the video

Subscribe for more Python & AI content

Comment your OS (Windows / Linux)

Channel: AI with Ali Husnain


On this page of the site you can watch the video online Remove Image Background Using Python | rembg Tutorial (Windows & Linux) | Beginner Friendly with a duration of hours minute second in good quality, which was uploaded by the user Ali Husnain 03 January 2026, share the link with friends and acquaintances, this video has already been watched 45 times on youtube and it was liked by 2 viewers. Enjoy your viewing!