On 13 October 2016 at 15:27, Arthur Goldberg <artgoldb...@gmail.com> wrote:
> Is there a recommended way to use pip, especially pip install, from within a
> program and obtain good error handling?

Nothing supported, sorry. The only supported interface is the command
line, so you can use subprocess.Popen to run pip in a subprocess. But
the pip API is for internal use only. (In particular, I'm not
surprised there's not a good interface for trapping errors from pip
APIs, it's not a usage we particularly consider). We're not against
*having* a supported API, it's just that no-one has put in the work to
define such a thing (and error handling would be an obvious thing we'd
need to consider :-)) or document and implement it (and create tests
for it) yet.

I assume, by the way, that you are aware of the risks of installing
new packages into site-packages from within a Python process? Most of
the time you should be OK, but Python does cache information within
the import system, and you do run the risk of getting stale data.
That's not a pip-specific issue, though, so it's something you should
be aware of regardless of how you call pip.


Reply via email to