8 ms·
> Can "pip install" actually run code? Indeed it can, and in fact has to by necessity in many cases: `pip install` boils down to (a variant of) `python setup.p
by woodruffw 3y ago
> Can "pip install" actually run code?
Indeed it can, and in fact has to by necessity in many cases: `pip install` boils down to (a variant of) `python setup.py install` for many packages, where `setup.py` is package-controlled arbitrary Python code.
This is also true for subcommands like `pip download`, as well as `pip install --dry-run`.
(There's some subtlety here, since this only applies to source distributions and not wheels. But source distributions are still the "baseline" way to distribute Python packages.)
> and a package needs to be imported by a script before anything gets run.
Even with wheels, this part is unfortunately not true: a package can install a `.pth` file[1], which can be used to auto-load code on Python interpreter startup, even if the malicious package itself is never imported directly.
[1]: https://docs.python.org/3/library/site.html https://docs.python.org/3/library/site.html