Python · Industrial Automation

Python Virtual Environment in VS Code: venv, pip & requirements.txt

Learn Python virtual environments in VS Code using venv, pip and requirements.txt. Create, activate, select and verify isolated environments for automation projects.

Practical Python Automation Context Copy-Paste Examples Code Architecture

Learning Overview

Python Learning SeriesPython for Industrial AutomationPractical

Learning Goal

  • Learn Python virtual environments in VS Code using venv, pip and requirements.txt. Create, activate, select and verify isolated environments for automation projects.
  • Run the examples in VS Code using the project environment prepared in earlier topics.
  • Understand where this topic fits in the complete SQL, reporting and Industry 4.0 workflow.
Quick answer

Learn Python virtual environments in VS Code using venv, pip and requirements.txt. Create, activate, select and verify isolated environments for automation projects.

Architecture: Virtual Environment + venv

Code-Based Architecture

Virtual Environment + venv

1

Project Folder

Keep dependencies with one project

mkdir SQF_Report
2

Create venv

Create isolated Python environment

python -m venv .venv
3

Activate

Use project Python and pip

.venv\Scripts\activate
4

Select Interpreter

Point VS Code to .venv

Python: Select Interpreter
5

Install Packages

Install only project dependencies

python -m pip install pyodbc pandas openpyxl
6

requirements.txt

Record/rebuild environment

python -m pip freeze > requirements.txt
Project FolderCreate venvActivateSelect InterpreterInstall Packagesrequirements.txt

1. Why use a virtual environment?

A virtual environment isolates one project’s Python packages from the global Python installation. This makes training PCs and production report projects more repeatable.

2. Create a project and venv

mkdir SQF_Report
cd SQF_Report
python -m venv .venv

The .venv folder contains a project-specific Python interpreter and site-packages.

3. Activate the environment in VS Code Terminal

.venv\Scripts\activate
python --version
python -m pip --version
After activation, the terminal prompt normally shows (.venv).

4. Install project packages

python -m pip install pyodbc pandas openpyxl pyinstaller
python -m pip list

5. Create and use requirements.txt

python -m pip freeze > requirements.txt
python -m pip install -r requirements.txt

The first command records versions; the second rebuilds them on another authorized PC.

6. readiness check

import sys
import pandas
import pyodbc
import openpyxl print("Python:", sys.executable)
print("pandas:", pandas.__version__)
print("pyodbc:", pyodbc.version)
print("openpyxl:", openpyxl.__version__)

Frequently Asked Questions

What is a Python virtual environment?

A virtual environment is an isolated Python environment for one project, with its own interpreter context and installed packages.

Should I install packages globally or in .venv?

For project work, prefer a virtual environment so dependencies are isolated and reproducible.

What is requirements.txt used for?

It records package requirements so the same project environment can be installed on another machine.

Reviewed by Bhawesh Kumar SinghIndustrial Automation Trainer and Industry 4.0 Consultant · Softwell Automation · 21+ years industry experience
Complete Python for Industrial Automation Learning Path

Use Previous / Next for sequential training, or open any topic directly.

Complete

Continue with the next topic in the Python for Industrial Automation learning path.

Open Learning Path
Python for Industrial Automation

Virtual Environment + venv

Learn Python virtual environments in VS Code using venv, pip and requirements.txt. Create, activate, select and verify isolated environments for automation projects.

Content reviewed: 14 September 2026

☎ Call WhatsApp ✉ Email Enquire Now