<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
p.msonormal0, li.msonormal0, div.msonormal0
{mso-style-name:msonormal;
mso-margin-top-alt:auto;
margin-right:0in;
mso-margin-bottom-alt:auto;
margin-left:0in;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
span.EmailStyle18
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri",sans-serif;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link="#0563C1" vlink="#954F72"><div class=WordSection1><p class=MsoNormal>I have a somewhat better, imo, implementation of a pip object to be loaded into the repl.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>class pip:<o:p></o:p></p><p class=MsoNormal> def __call__(self, *a, **kw):<o:p></o:p></p><p class=MsoNormal> sys.stderr.write(str(self))<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal> def __repr__(self):<o:p></o:p></p><p class=MsoNormal> return str(self)<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal> def __str__(self):<o:p></o:p></p><p class=MsoNormal> return “Please run pip from your system command prompt”<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><div style='border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt'><div><div style='border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in'><p class=MsoNormal><b>From:</b> Python-ideas [mailto:python-ideas-bounces+tritium-list=sdamon.com@python.org] <b>On Behalf Of </b>Stephan Houben<br><b>Sent:</b> Sunday, October 29, 2017 3:19 PM<br><b>To:</b> Python-Ideas <python-ideas@python.org><br><b>Subject:</b> [Python-ideas] install pip packages from Python prompt<o:p></o:p></p></div></div><p class=MsoNormal><o:p> </o:p></p><div><div><div><div><div><div><div><div><p class=MsoNormal style='margin-bottom:12.0pt'>Hi all,<o:p></o:p></p></div><p class=MsoNormal>Here is in somewhat more detail my earlier proposal for<o:p></o:p></p></div><p class=MsoNormal>having in the interactive Python interpreter a `pip` function to <o:p></o:p></p></div><p class=MsoNormal style='margin-bottom:12.0pt'>install packages from Pypi.<o:p></o:p></p></div><p class=MsoNormal>Motivation: it appears to me that there is a category of newbies<o:p></o:p></p></div><p class=MsoNormal style='margin-bottom:12.0pt'>for which "open a shell and do `pip whatever`" is a bit too much.<o:p></o:p></p></div><div><p class=MsoNormal>It would, in my opinion, simplify things a bit if they could just<o:p></o:p></p></div><div><p class=MsoNormal>copy-and-paste some text into the Python interpreter and have<o:p></o:p></p></div><div><p class=MsoNormal>some packages from pip installed. <o:p></o:p></p></div><div><p class=MsoNormal>That would simplify instructions on how to install package xyz,<o:p></o:p></p></div><div><p class=MsoNormal>without going into the vagaries of how to open a shell on various <o:p></o:p></p></div><div><p class=MsoNormal style='margin-bottom:12.0pt'>platforms, and how to get to the right pip executable.<o:p></o:p></p></div><div><p class=MsoNormal>I think this could be as simple as:<br><br> def pip(args):<br> import sys<br> import subprocess<br> subprocess.check_call([sys.executable, "-m", "pip"] + args.split())<o:p></o:p></p></div><div><p class=MsoNormal style='margin-bottom:12.0pt'> print("Please re-start Python now to use installed or upgraded packages.")<o:p></o:p></p></div><div><p class=MsoNormal>Note that I added the final message about restarting the interpreter<o:p></o:p></p></div><div><p class=MsoNormal>as a low-tech solution to the problem of packages being already<o:p></o:p></p></div><div><p class=MsoNormal style='margin-bottom:12.0pt'>imported in the current Python session.<o:p></o:p></p></div><div><p class=MsoNormal>I would imagine that the author of package xyz would then put on<o:p></o:p></p></div><div><p class=MsoNormal style='margin-bottom:12.0pt'>their webpage something like:<o:p></o:p></p></div><div><p class=MsoNormal> To use, enter in your Python interpreter:<o:p></o:p></p></div><div><p class=MsoNormal style='margin-bottom:12.0pt'> pip("install xyz --user")<o:p></o:p></p></div><div><p class=MsoNormal>As another example, consider prof. Baldwin from Woolamaloo university<o:p></o:p></p></div><div><p class=MsoNormal style='margin-bottom:12.0pt'>who teaches a course "Introductory Python programming for Sheep Shavers".<o:p></o:p></p></div><div><p class=MsoNormal>In his course material, he instructs his students to execute the<o:p></o:p></p></div><div><p class=MsoNormal style='margin-bottom:12.0pt'>following line in their Python interpreter.<o:p></o:p></p></div><div><p class=MsoNormal style='margin-bottom:12.0pt'> pip("install woolamaloo-sheepshavers-goodies --user")<o:p></o:p></p></div><div><p class=MsoNormal>which will install a package which will in turn, as dependencies,<o:p></o:p></p></div><div><p class=MsoNormal>pull in a number of packages which are relevant for sheep shaving but<o:p></o:p></p></div><div><p class=MsoNormal style='margin-bottom:12.0pt'>which have nevertheless irresponsibly been left outside the stdlib.<o:p></o:p></p></div><div><p class=MsoNormal>Stephan<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal style='margin-bottom:12.0pt'><o:p> </o:p></p></div></div></div></div></div></body></html>