classification
Title: Add a method to pip.. pip.require("package_name")
Type: enhancement Stage: resolved
Components: Versions:
process
Status: closed Resolution: third party
Dependencies: Superseder:
Assigned To: Nosy List: Blaize Rhodes, berker.peksag, matrixise
Priority: normal Keywords:

Created on 2016-01-10 10:52 by Blaize Rhodes, last changed 2016-01-23 22:08 by Blaize Rhodes. This issue is now closed.

Files
File name Uploaded Description Edit
require.py Blaize Rhodes, 2016-01-10 10:51 Attached is some code that illustrates the idea.
Messages (5)
msg257903 - (view) Author: Blaize Rhodes (Blaize Rhodes) Date: 2016-01-10 10:51
The idea is to add a method to pip that tries to import a package and if the import fails then try to download and install the package handling the UI.

Yes, you can put the package as a dependency in your pip config for 
your code.  This is intended for the case when you have a bunch of 
python tools/libs in some shared repository in your organization.
People check the code out and expect it to run but it has third party 
dependencies.  There is no install step for your code, per se.  Furthermore the people using your code don't know enough about python to install things themselves.

Proposed syntax is:

import pip
pip.require("foo")

If you search online for pip.main you'll see a whole bunch of hall-baked brittle solutions to this problem that look like this:

try:
    import foo
except ImportError:
     pip.main("install", "foo")
msg257904 - (view) Author: Blaize Rhodes (Blaize Rhodes) Date: 2016-01-10 10:55
I'm more than happy to fill in the contributor agreement.. but it seems like a hassle if, what I'm assuming will happen, someone points out a good reason why this hasn't been done already.
msg257907 - (view) Author: St├ęphane Wirtel (matrixise) * (Python committer) Date: 2016-01-10 12:26
But in fact, Pip is an external project to CPython.

Could you explain why you post this issue in the CPython Bug Tracker?

Thank you
msg257922 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2016-01-10 17:40
Thanks for the report, but this should be discussed either at https://groups.google.com/forum/#!forum/pypa-dev or https://github.com/pypa/pip/issues
msg258876 - (view) Author: Blaize Rhodes (Blaize Rhodes) Date: 2016-01-23 22:08
Righto.. will talk to the pip dudes.  Thanks for your time.  

(@matrixise The reason I posted this here is because pip is included as part of the cpython distribution.  None of the documentation I've seen suggests that this isn't a forum for discussing the std python libs, and indeed there seem to be many enhancement requests for python libs in this bug db.  It seems that pip has some special status as included as part of the std python distribution but not part of the std libs.  I would have thought that it was obvious from the context that I was unaware of this fact at the time I posted the request.  Does that answer your question?  What's with the attitude?  You've never made a mistake I take it?).
History
Date User Action Args
2016-01-23 22:08:55Blaize Rhodessetmessages: + msg258876
2016-01-10 17:40:00berker.peksagsetstatus: open -> closed

nosy: + berker.peksag
messages: + msg257922

resolution: third party
stage: resolved
2016-01-10 12:26:36matrixisesetnosy: + matrixise
messages: + msg257907
2016-01-10 10:55:37Blaize Rhodessetmessages: + msg257904
2016-01-10 10:52:00Blaize Rhodescreate