Virtual Environments
Virtual environments are isolated Python environments that allow you to install and manage packages for specific projects without affecting your system-wide Python installation.
To create a virtual environment, use the following command:
python -m venv myenv
This creates a new virtual environment named "myenv" in your current directory.
To activate the virtual environment:
# On Windows
myenv\Scripts\activate
# On macOS and Linux
source myenv/bin/activate
Once activated, you can install packages using pip without affecting your global Python installation:
pip install package_name
To exit the virtual environment, simply run:
deactivate
While venv is built into Python, there are other popular tools for managing virtual environments:
Virtual environments are an essential tool for Python developers, ensuring clean, reproducible, and isolated development environments for each project.