PEP 722: Dependency specification for single-file scripts

Just a hypothetical: given that pip is available with most Python distributions, if pip had a minimal, importable API, would this even be necessary? Could this use case be handled by something like:

#!/usr/bin/env python

# In order to run, this script needs the following 3rd party libraries
import pip
pip.install(["requests", "rich"])

import requests
from rich.pretty import pprint
...

And if so, would that be preferable to comments with side effects?

9 Likes