Virtual Environments in Python
To effectively manage your Python dependencies, we recommend using a Python Virtual Environment.
Setting up a Virtual Environment
Prerequisites
Ensure you have Python installed on your system. You can check if Python is installed by running:
If Python is not installed, download and install it from the official Python website.
Creating a Virtual Environment
To get started with using a virtual environment, follow these steps:
-
Open your Terminal Emulator of choice.
-
Navigate to your desired project directory:
- Create a virtual environment by running:
This will create a directory named .venv
containing the virtual environment.
Activating the Virtual Environment
- On Windows, run:
- On macOS and Linux, run:
After activation, your terminal prompt should change to indicate that you are now using the virtual environment.
Installing Dependencies
Once the virtual environment is activated, you can install the required dependencies using pip
. To install dependencies, run the following command in your activated virtual environment terminal:
Deactivating the Virtual Environment
To deactivate the virtual environment and return to the global Python environment, simply run:
By following these steps, you can create, activate, manage, and deactivate a virtual environment in Python, ensuring that your project dependencies remain organized and isolated.