Virtual Env

A virtual environment is an isolated Python system.
 
python -m pip install --upgrade pip
pip install virtualenv

virtualenv ./my_env     # create

. my_env/bin/activate   # load and activate
pip list                # test env     
deactivate              # exit env

source my_env/bin/activate # second method
pip list
deactivate

: '
Package    Version
---------- -------
pip        22.3.1
setuptools 65.6.3
wheel      0.38.4
'
        
echo 'my_env/' > .gitignore

Venv

Use the venv module which is included in the standard library.
 
python3 -m venv myenv

myenv\Scripts\activate # windows

source myenv/bin/activate # linux

Requirements

Save the list for requirements in order to used later (or on another computer).
 
(.venv) pip freeze > requirements.txt
(.venv) pip install -r requirements.txt

Python Upgrade (Windows)

1. Download Python

Go to the official Python website: https://www.python.org/downloads/windows/ Download the “Windows x86-64 executable installer” (64-bit is standard for servers). You just need to use the right installer and options. The installer contains everything Python needs. Download exactly this file:
 
Windows x86-64 executable installer
python-3.12-amd64.exe

2. Install

Run the installer -> Run as Administrator Add Python to PATH. Unblock the File: Windows marks files copied from another machine as 'from the internet' even if transferred by USB. Solution: - Right‑click python-3.13.0-amd64.exe - Properties - Check Unblock - Click OK - Run installer again Python on Windows is designed to support multiple versions installed at the same time. In Path, move the new version above the old one.
 
python --version

3. Virtual Environments

Each project uses its own Python version.
 
C:\Python312\python.exe -m venv venv312
venv312\Scripts\activate
Upgrade pattern (production-safe): - Install new Python side‑by‑side (PATH) - Create new venv with it - Reinstall dependencies - Switch service / app to new venv - Remove old venv when stable

3.1 Create a new virtual environment

From the application root directory:
 
"D:\Program Files\Python312\python.exe" -m venv venv312

venv312\Scripts\python.exe --version
# Python 3.12.0

3.2 Reinstall dependencies

 
cd D:\python-apps\pof_statistics\
.\venv312\Scripts\activate

(venv312) 
python.exe -m pip install --upgrade pip
pip install -r requirements.txt




References: