A virtual environment is a self-contained directory containing a Python interpreter, pip, and additional packages. Its isolated libraries prevent conflicts with system Python or other projects, so applications can use different Python and package versions. section 19.5.2
Create and use one in two steps:
- Create it with `python -m venv test-env`. section 19.5.2
- Activate it with `test-env\Scripts\activate.bat` on Windows or `source test-env/bin/activate` on Unix and macOS. section 19.5.2
- After activation, install packages with pip, such as `pip install requests`; the environment's Python version remains the one used during creation. section 19.5.2
Project-specific requests installation
Run `python -m venv test-env`, activate `test-env`, then run `pip install requests`. The resulting package belongs to that environment rather than the system installation. section 19.5.2
myuser@mymachine$ python -m venv test-env
Use the command listing to create a `test-env` directory with Python and pip installed. section 19.5.2
(test-env) myuser@mymachine$ pip install requests #1
Use the activated prompt to install `requests` inside the virtual environment. section 19.5.2
Virtual environments are standard practice for managing dependencies across multiple projects. Colaboratory sessions are temporary environments, so they generally do not require separate virtual-environment management. section 19.5 section 19.5.2






