
If you are calling pip.main, you know what you are doing, and you know when you have to restart the interpreter or not. An object that displays an error any time you try to use it, instructing a user of the proper way to use pip outside of the interpreter, is intended to catch the newbie mistake of trying to run pip from inside the repl, without encouraging potentially problematic behavior related to calling pip from inside the interpreter. Don’t encourage the wrong way because it’s a common newbie mistake, give them better documentation and error messages. Pip is a tool to be run outside of the repl, let’s keep it that way. My method avoids the entire problem by not attempting to run pip, while still providing a meaningful and useful error message to new users. If there is to be a solution other than SyntaxError or NameError (my solution only solves NameError), it should be to tell users how to use pip properly, not support improper use. From: Python-ideas [mailto:python-ideas-bounces+tritium-list=sdamon.com@python.org] On Behalf Of Antoine Rozo Sent: Sunday, October 29, 2017 3:32 PM To: Python-Ideas <python-ideas@python.org> Subject: Re: [Python-ideas] install pip packages from Python prompt Hi, What would be the difference with current pip module? pip.main(['install', 'some_package']) 2017-10-29 20:26 GMT+01:00 Alex Walters <tritium-list@sdamon.com <mailto:tritium-list@sdamon.com> >: I have a somewhat better, imo, implementation of a pip object to be loaded into the repl. class pip: def __call__(self, *a, **kw): sys.stderr.write(str(self)) def __repr__(self): return str(self) def __str__(self): return “Please run pip from your system command prompt” From: Python-ideas [mailto:python-ideas-bounces+tritium-list <mailto:python-ideas-bounces%2Btritium-list> =sdamon.com@python.org <mailto:sdamon.com@python.org> ] On Behalf Of Stephan Houben Sent: Sunday, October 29, 2017 3:19 PM To: Python-Ideas <python-ideas@python.org <mailto:python-ideas@python.org> > Subject: [Python-ideas] install pip packages from Python prompt Hi all, Here is in somewhat more detail my earlier proposal for having in the interactive Python interpreter a `pip` function to install packages from Pypi. Motivation: it appears to me that there is a category of newbies for which "open a shell and do `pip whatever`" is a bit too much. It would, in my opinion, simplify things a bit if they could just copy-and-paste some text into the Python interpreter and have some packages from pip installed. That would simplify instructions on how to install package xyz, without going into the vagaries of how to open a shell on various platforms, and how to get to the right pip executable. I think this could be as simple as: def pip(args): import sys import subprocess subprocess.check_call([sys.executable, "-m", "pip"] + args.split()) print("Please re-start Python now to use installed or upgraded packages.") Note that I added the final message about restarting the interpreter as a low-tech solution to the problem of packages being already imported in the current Python session. I would imagine that the author of package xyz would then put on their webpage something like: To use, enter in your Python interpreter: pip("install xyz --user") As another example, consider prof. Baldwin from Woolamaloo university who teaches a course "Introductory Python programming for Sheep Shavers". In his course material, he instructs his students to execute the following line in their Python interpreter. pip("install woolamaloo-sheepshavers-goodies --user") which will install a package which will in turn, as dependencies, pull in a number of packages which are relevant for sheep shaving but which have nevertheless irresponsibly been left outside the stdlib. Stephan _______________________________________________ Python-ideas mailing list Python-ideas@python.org <mailto:Python-ideas@python.org> https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/ -- Antoine Rozo