a day ago
- Virtual environments isolate Python packages, preventing system pollution and conflicts.
- Create a virtual environment with `python -m venv <env-name>`; activate by sourcing `bin/activate`.
- While active, install packages using `pip install`; they are confined to the environment.
- Deactivate with `deactivate` or by exiting the shell; delete the environment directory to remove it.
- Run scripts directly using the venv's Python path (e.g., `/path/to/venv/bin/python script.py`) without activation.
- Third-party tools like `uv` can streamline virtual environment management.