This video provides a comprehensive tutorial on Python virtual environments. It explains their purpose, demonstrates their creation and use, and shows how to recreate environments using a requirements.txt file. The tutorial aims to help viewers manage project-specific dependencies effectively.
venv module (other options like Poetry are mentioned). Commands vary slightly depending on the operating system (Mac vs. Windows).pip.requirements.txt: The video explains how to create and use a requirements.txt file to document and reproduce a project's environment, avoiding the need to version control the entire virtual environment.The video demonstrates several terminal commands, primarily for macOS, with brief mentions of Windows equivalents. Here's a summary:
macOS Commands:
cd projectA: Changes the directory to the "projectA" folder. Similar commands (cd projectB, cd projectC) are used to navigate to other project folders.python3.11 -m venv .venvA: Creates a virtual environment named ".venvA" using Python 3.11 in the current directory. Similar commands (with variations in Python version and environment name) are used to create environments for projects B and C (python3.11 -m venv .venvB, python3.12 -m venv .venvC).source .venvA/bin/activate: Activates the ".venvA" virtual environment. Similar commands (with variations in environment name) are used to activate environments for projects B and C.python --version: Checks the active Python version.pip list: Lists all installed packages in the active environment.pip install pandas==2.2: Installs pandas version 2.2 in the active environment. A similar command installs pandas version 1.5 in project B's environment.deactivate: Deactivates the active virtual environment.pip freeze > requirements_c.txt: Creates a requirements_c.txt file containing a list of all installed packages and their versions in the active environment.pip install -r requirements_c.txt: Installs all packages listed in requirements_c.txtWindows Commands (briefly mentioned):
The video notes that the syntax for creating and activating virtual environments on Windows differs from macOS. Specific commands are not shown, only the statement that they are different.