Skip to content

FlameAutomation/Hello-Step7

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

How to Set Up a Python Virtual Environment

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.


What You'll Learn

  • 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

Prerequisites

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)

Step 1: Check Python Versions

Run the following in your terminal:

py -0

You’ll see all installed Python versions, like:

Available Python versions:
 * 3.12
   3.10

Take note of the 3.10 path.


Step 2: Create a Virtual Environment Using Python 3.10

Use this command to create a clean environment named mediapipe-env:

py -3.10 -m venv mediapipe-env

This creates a folder mediapipe-env/ with isolated Python and pip.


Step 3: Activate the Virtual Environment

PowerShell:

.\mediapipe-env\Scripts\activate

CMD:

mediapipe-env\Scripts\activate.bat

You should now see the environment name in your terminal like this:

(mediapipe-env) PS C:\Users\YourName\YourProject>

Step 4: Upgrade pip

Always upgrade pip to avoid old dependency issues:

pip install --upgrade pip

Step 5: Install Required Packages

Now install your packages (e.g. for a voice/video processing project):

pip install python-snap7 speechrecognition pyttsx3 opencv-python mediapipe

mediapipe currently 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.

Step 6: Deactivate When Done

After working, you can deactivate the virtual environment:

deactivate

Troubleshooting Tips

Could not find a version that satisfies the requirement mediapipe

You're probably using Python 3.12 — switch to Python 3.10.

'Scripts\activate' is not recognized...

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\activate

Conclusion

Using a virtual environment:

  • Keeps your project dependencies isolated
  • Prevents conflicts between Python versions and libraries
  • Helps you use packages like mediapipe that 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.


Loading..

About

Siemens S7 PLC Communication

Topics

Resources

Code of conduct

Stars

Watchers

Forks

Languages