• Overview
  • Control Theory
  • Python
  • TwinCAT
  • Profile
  1. Python
  2. How to create a Python virtual environment

  • Python
    • How to create a Python virtual environment

On this page

  • 1 Navigate to your project directory
    • 1.1 Option A: Via File Explorer
    • 1.2 Option B: Via Command Prompt
  • 2 Create a virtual environment
  • 3 Activate the environment
  • 4 Install packages
    • 4.1 Individual Installation
    • 4.2 Batch Installation (using requirements.txt)
  • 5 Deactivate the environment
  • 6 Configure your IDE
  1. Python
  2. How to create a Python virtual environment

How to create a Python virtual environment

A virtual environment works in only a specified folder, and doesn’t influence other environments. By using it, you can avoid version conflicts of Python packages between different projects.

Follow these steps to set up your environment quickly.


1 Navigate to your project directory

First, move to the folder where you want to create your virtual environment.

1.1 Option A: Via File Explorer

Enter cmd in the address bar of your development folder and press Enter.

1.2 Option B: Via Command Prompt

Use the cd command:

cd [Your-Project-Address]

2 Create a virtual environment

Enter the following command to create a environment folder named .venv.

py -m venv .venv

[!TIP] Specific Python Version
If you have multiple versions installed, specify one like this: py -3.xx -m venv .venv


3 Activate the environment

To start using the virtual environment, you need to activate it.

.venv\Scripts\activate

Verify the activation: Check which Python version is currently active:

py -V

4 Install packages

Once activated, you can manage your libraries without affecting the global system.

4.1 Individual Installation

pip install [Package Name]

To install a specific version:

pip install [Package Name]==[Version No.]

4.2 Batch Installation (using requirements.txt)

  1. Export existing list:
    pip freeze > requirements.txt
  2. Install from list:
    pip install -r requirements.txt

[!NOTE] You can confirm the list of installed packages anytime using: pip list


5 Deactivate the environment

When you are finished working, exit the virtual environment with:

deactivate

6 Configure your IDE

To make the most of your virtual environment, set the Python interpreter in your IDE (e.g., VS Code or PyCharm).

Interpreter Path: .venv\Scripts\python.exe

© Koichi Sakata 2026

Built with Quarto