JetBrains Fleet
 

Running code using a virtual environment

Last modified: 27 November 2024

This article demonstrates the use of Python's venv module to create and manage isolated virtual environments. It includes setting up a virtual environment, installing dependencies, freezing dependencies to a requirements.txt file, and running a sample Python script that uses an external library.

  • Isolation: ensures that the project's dependencies do not interfere with other projects.

  • Portability: easily share and recreate the environment on different machines.

  • Dependency management: use pip to install and manage project-specific dependencies.

  • Reproducibility: share the exact environment setup using requirements.txt.