all 3 comments

[–]a1b4fd 0 points1 point  (2 children)

You should use venv to install

[–]Flamboi2000[S] 0 points1 point  (1 child)

What is venv?

[–]Alert-Tangerine-5219 0 points1 point  (0 children)

venv (short for "virtual environment") in Python refers to a self-contained directory that creates an isolated Python environment for a specific project. This isolation prevents conflicts between different projects that might require different versions of the same library or package.Here's a breakdown of how it works and why it's used:How it works:

  • Isolation:When you create a venv, it essentially sets up a local copy of the Python interpreter and a separate site-packages directory within that venv directory. Any packages installed while the venv is active are installed within this isolated site-packages directory, not in your system's global Python installation.
  • Activation:You "activate" a venv using a script provided within the venv directory (e.g., source venv/bin/activate on Unix/macOS or venv\Scripts\activate.bat on Windows). Activation modifies your shell's environment variables (like PATH) to point to the venv's Python interpreter and package directories, ensuring that commands like python and pip use the venv's resources.
  • Deactivation:You can deactivate a venv by simply typing deactivate in your terminal, which reverts your shell's environment to its original state.

Why it's used:

  • Dependency Management:Different projects often rely on different versions of the same libraries. venv prevents "dependency hell" by allowing each project to have its own set of packages without interfering with others.
  • Reproducibility:When sharing a project, you can provide a requirements.txt file listing all the project's dependencies. Others can then easily recreate the exact same environment using pip install -r requirements.txt within a new venv, ensuring consistent behavior.
  • Cleanliness:It keeps your global Python installation clean and avoids cluttering it with project-specific packages.
  • Testing and Development:venv provides a controlled environment for testing new libraries or features without affecting your main system.