pip install, list, and Virtual Environments
pip is Python's package manager. Use pip install to add packages, pip list to see installed ones. Virtual environments (venv) keep project dependencies isolated.
# In your terminal (not Python):
# python -m venv myenv
# myenv\Scripts\activate (Windows)
# source myenv/bin/activate (macOS/Linux)
# pip install requests # install a package
# pip list # list installed packages
# pip freeze > requirements.txt # save dependencies
# In Python code after installing:
import requests
response = requests.get("https://api.example.com")
print(response.status_code)
Try it Yourself โ