If you're new to Python and want to use libraries like mediapipe, OpenCV, or speechrecognition, setting up a virtual environment is the safest and cleanest way to manage your projects. This guide walks you through the entire process, even if you're using multiple Python versions.
- How to check your Python versions
- How to create a virtual environment with a specific Python version
- How to activate the environment
- How to install required libraries
- How to troubleshoot common issues
Before you start, make sure you:
- Have Python 3.10.x installed (not just 3.12+)
- Are using Windows with PowerShell or CMD
- Have access to a terminal (like VS Code's Terminal or Command Prompt)
Run the following in your terminal:
py -0You’ll see all installed Python versions, like:
Available Python versions:
* 3.12
3.10
Take note of the 3.10 path.
Use this command to create a clean environment named mediapipe-env:
py -3.10 -m venv mediapipe-envThis creates a folder mediapipe-env/ with isolated Python and pip.
PowerShell:
.\mediapipe-env\Scripts\activateCMD:
mediapipe-env\Scripts\activate.batYou should now see the environment name in your terminal like this:
(mediapipe-env) PS C:\Users\YourName\YourProject>Always upgrade pip to avoid old dependency issues:
pip install --upgrade pipNow install your packages (e.g. for a voice/video processing project):
pip install python-snap7 speechrecognition pyttsx3 opencv-python mediapipe
mediapipecurrently does not support Python 3.12+, so using Python 3.10 is essential here.
| Library | Purpose | Use Case |
|---|---|---|
python-snap7 |
Siemens S7 PLC communication | Connect and exchange data with industrial PLCs using Snap7 protocol |
SpeechRecognition |
Speech-to-text conversion | Convert spoken language into text using microphone or audio files |
pyttsx3 |
Text-to-speech (TTS) synthesis | Convert text into spoken audio (offline support) |
opencv-python |
Computer vision | Image processing, video capture, object/face detection |
mediapipe |
Machine learning-based perception pipelines | Real-time face detection, hand tracking, pose estimation, etc. |
After working, you can deactivate the virtual environment:
deactivateYou're probably using Python 3.12 — switch to Python 3.10.
You may be:
- In the wrong folder
- Misspelling the path (e.g., missing
.\) - Trying to activate an environment that doesn’t exist
Check that the mediapipe-env folder exists and use:
.\mediapipe-env\Scripts\activateUsing a virtual environment:
- Keeps your project dependencies isolated
- Prevents conflicts between Python versions and libraries
- Helps you use packages like
mediapipethat don't yet support the latest Python versions
Start using this setup for all your Python projects, and you'll avoid many common headaches down the line.