To start experimenting with computer vision, you'll need a place to write and run code. This involves setting up a development environment on your computer. Think of this as preparing your digital workbench with the necessary tools. The Python programming language along with a few specialized libraries are widely adopted in computer vision.
Python is a popular choice due to its readability, extensive collection of libraries, and strong community support. Libraries are pre-written collections of code that provide functionalities we can readily use, saving us from writing everything from scratch.
Before installing anything, it's highly recommended to create an isolated environment for your project. Why? Different projects might require different versions of the same library. Installing everything globally (directly into your main Python installation) can lead to conflicts down the line. A virtual environment acts like a self-contained workspace for each project, keeping its dependencies separate.
We'll need the following components:
pip to install the required libraries.venv for creating virtual environments.Let's walk through the setup process using the command line or terminal.
Open Your Terminal or Command Prompt:
cmd or PowerShell.Terminal application (found in Applications > Utilities).gnome-terminal, konsole).Create a Project Directory: It's good practice to have a dedicated folder for your course work.
# Create a directory (e.g., 'cv_intro') and navigate into it
mkdir cv_intro
cd cv_intro
Create a Virtual Environment: We'll use Python's built-in venv module. We'll name our environment env (a common convention).
# On macOS/Linux
python3 -m venv env
# On Windows
python -m venv env
This command creates a new directory named env containing a copy of the Python interpreter and a place to install libraries.
Activate the Virtual Environment: You need to activate the environment each time you work on the project in a new terminal session.
# On macOS/Linux (bash/zsh)
source env/bin/activate
# On Windows (Command Prompt)
.\env\Scripts\activate.bat
# On Windows (PowerShell)
.\env\Scripts\Activate.ps1
Once activated, your terminal prompt will usually change to show the environment name (e.g., (env) Your-Computer:cv_intro user$). This indicates that python and pip commands will now use the versions within this isolated environment.
Install Libraries: Now, use pip to install OpenCV, NumPy, and Matplotlib. We'll install the main OpenCV module (opencv-python) which includes NumPy as a dependency, and also Matplotlib.
pip install opencv-python matplotlib
pip will download and install the specified packages and their dependencies into your active virtual environment.
Verify the Installation: A quick way to check if everything is installed correctly is to start a Python interpreter and try importing the libraries.
python (or python3 on some systems) in your activated terminal and press Enter. You should see the Python prompt (>>>).>>> import cv2
>>> import numpy
>>> import matplotlib
>>> print(cv2.__version__)
# Expected output: A version number, e.g., 4.9.0 (or similar)
>>> exit()
If you don't get any ModuleNotFoundError messages and the cv2.__version__ command prints a version number, your environment is ready! Type exit() to leave the Python interpreter.
Note on OpenCV Packages: You might see different OpenCV packages available via pip (e.g.,
opencv-contrib-python). For this introductory course,opencv-pythoncontains the core functionalities we need. Thecontribpackage includes additional, often experimental, modules.
Many in data science and machine learning prefer using Anaconda, which is a distribution of Python and R that includes its own package manager (conda) and environment management system. If you already use Anaconda, you can create an environment and install packages using:
# Create a new environment named 'cv_intro_env' with python
conda create --name cv_intro_env python=3.9 # Or your preferred Python 3 version
# Activate the environment
conda activate cv_intro_env
# Install libraries (often uses different channel configurations)
conda install -c conda-forge opencv numpy matplotlib
While Anaconda is powerful, for simplicity and standard Python practice, we'll primarily refer to the pip and venv method throughout this course. Choose the method you are most comfortable with.
You now have a working Python environment equipped with the essential tools for computer vision. In the next section, we'll use this setup to load and display our first digital image. Remember to activate your virtual environment (source env/bin/activate or .\env\Scripts\activate) whenever you start a new terminal session to work on the course exercises.
Was this section helpful?
© 2026 ApX Machine LearningEngineered with