Should I use pip.main() or subprocess.call() to invoke pip commands?

In general

Do not call somebody else's main() unless you want to give them ownership of the process. They could, for example, call sys.exit() or one of the os.exec*() functions. They could also install signal handlers, change the umask, or make all sorts of other global changes to your process's state. If you don't want them to do such things, you should run their code in a subprocess instead.

(Of course, library code can do all of the above just as easily, but it's considered "rude" to do so without documenting it, whereas the author of a main() function typically assumes they have the whole process to themself.)

For Pip in particular

pip.main() is not a public interface, and is unsupported. Use a subprocess.


It depends. pip is undocumented and may not be backwards compatible. I recommend using subprocess instead, as the basic semantics of pip are unlikely to be changed in the near future.