(Progress persistence is disabled until Phase 9)
Virtual Environments and Packages
Manage dependencies for your projects.
Virtual Environments and Packages
What You’ll Learn
You’ll learn how to use pip to install third-party packages and how to isolate your projects using Virtual Environments.
Using pip
pip is the package installer for Python. It allows you to download libraries built by other developers from the Python Package Index (PyPI).
For example, to install the popular requests library for making HTTP requests, run this in your terminal:
pip install requests
Then, use it in your code:
import requests
response = requests.get("https://api.github.com")
print(response.status_code)
What is a Virtual Environment?
Imagine you have App A that needs version 1.0 of a library, and App B that needs version 2.0. If you install everything globally, the versions will conflict.
A Virtual Environment (venv) solves this by creating an isolated folder for each project where its specific dependencies live.
Creating and Activating a venv
In your terminal, navigate to your project folder:
# Create the environment (creates a folder called 'venv')
python -m venv venv
# Activate it (Windows)
venv\Scripts\activate
# Activate it (Mac/Linux)
source venv/bin/activate
Once activated, any pip install command will only install into this specific project folder!