question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Create a supported "high level" programmatic API for pip

See original GitHub issue

This has come up a few times recently now that pip is available in a standard Python install.

Maybe we should formally support a programmatic API for pip that allows the high-level command line operations pip supports to be run from within a Python interpreter? That may simply mean blessing (and documenting) pip.main() as a supported API.

There may be some odd corner cases to take care with, if we’re considering people running pip.main() from within a persistent interpreter (e.g. IPython or Idle). I’m thinking of cases where sys.modules caches something you’re upgrading, for example. But that may just need documentation saying that those things need an interpreter restart, at least as a starting point.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:4
  • Comments:32 (22 by maintainers)

github_iconTop GitHub Comments

1reaction
pfmoorecommented, Sep 21, 2015

I think there’s enough people talking about using pip from within Python (either prompts or scripts) that we should provide something. Even if it’s very limited, at least that will get people thinking about what exactly they need, and we’ll be able to firm up on details as we go along.

@dstufft for lower-level API’s based around the standards PEPs, we should absolutely be pointing people at packaging.

@RonnyPfannschmidt you have a good point. It’s not at all unreasonable to tell people that to call pip they should be using

subprocess.check_call([sys.executable, '-m', 'pip', ...])

If that’s not sufficient for them (for example, the format of stdout isn’t useful for parsing) we can discuss options (for example, adding a --json argument to informational commands).

On the other hand, I think the big issue is that people expect to be able to do

pip.main(['install', 'foo'])
import foo

from within (say) an Idle session. This is actually no different in principle from running pip in a separate command window and not restarting your Idle session (and indeed it’s exactly the same if you use subprocess) but maybe just documenting that is sufficient - after all, it’s not really a pip issue that you have to take care if you change the contents of sys.path while your Python process is running.

I think I’ll write up a new section for the pip documentation on the basis of subprocess being pip’s supported API. That can be a starting point for people wanting to integrate pip into IDEs, and we can then address any issues as people find them.

0reactions
pradyunsgcommented, May 28, 2020

That is appropriate, as long as folks using it don’t expect it to “just work”. Further, as noted in the README of that package:

The authors of pip do not condone the use of this package. Relying on pip’s internals is a dangerous idea for your software as they are broken intentionally and regularly. This package may not always be completely updated [snip], so relying on it may break your code! User beware!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Picture-in-picture (PiP) support
Starting in Android 8.0 (API level 26), Android allows activities to launch in picture-in-picture (PiP) mode. PiP is a special type of multi-window...
Read more >
panoptes-client
This module is intended to allow programmatic management of projects, providing high level access to the API for common project management tasks.
Read more >
Get Started | Ad Manager API
The Google Ad Manager API provides methods for managing Ad Manager inventory, creating orders, pulling reports, and more.
Read more >
Cloud Support API user guide - Documentation
This section details the high-level process for getting started with the API. Customer Care team creates a support account for the customer.
Read more >
Nicole Harris
We want you to try to break pip's new dependency resolver. ... Create a supported "high level" programmatic API for pip · Issue...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found