Installing libraries: pip
Theory
Machine translation, not yet reviewed by a native speaker.
The standard library is big, but thousands of other libraries are written by developers themselves. They live in the PyPI catalogue (pypi.org) and are installed with a program called pip.
These commands are typed in the terminal, not in Python code:
pip install requests # install
pip install requests==2.32.3 # a specific version
pip install --upgrade requests
pip uninstall requests
pip list # what's installed
pip show requests # details about a package
Once installed, a library is imported with an ordinary import:
import requests
r = requests.get("https://api.github.com")
print(r.status_code)
The requirements.txt file. It's customary to keep a project's dependencies in a file:
Django>=5.2,<6
requests==2.32.3
Install everything at once: pip install -r requirements.txt. Save the current environment: pip freeze > requirements.txt.
How this applies to our platform. Python here runs right in the browser (Pyodide), so the ordinary pip isn't available in the tasks. But this platform is itself a Django project, and its dependencies are installed exactly with pip install -r requirements.txt.
Be careful: install only well-known packages and check the name. Attackers publish packages with similar names (reqeusts instead of requests).