
On Mon, 30 Oct 2017 at 03:36 Erik Bray <erik.m.bray@gmail.com> wrote:
On Sun, Oct 29, 2017 at 8:45 PM, Alex Walters <tritium-list@sdamon.com> wrote:
Then those users have more fundamental problems. There is a minimum level of computer knowledge needed to be successful in programming. Insulating users from the reality of the situation is not preparing them to be successful. Pretending that there is no system command prompt, or shell, or whatever platform specific term applies, only hurts new programmers. Give users an error message they can google, and they will be better off in
On Mon, Oct 30, 2017 at 11:27 AM, Erik Bray <erik.m.bray@gmail.com> wrote: the
long run than they would be if we just ran pip for them.
While I completely agree with this in principle, I think you overestimate the average beginner. Many beginners I've taught or helped, even if they can manage to get to the correct command prompt, often don't even know how to run the correct Python. They might often have multiple Pythons installed on their system--maybe they have Anaconda, maybe Python installed by homebrew, or a Python that came with an IDE like Spyder. If they're on OSX often running "python" from the command prompt gives the system's crippled Python 2.6 and they don't know the difference.
I should add--another case that is becoming extremely common is beginners learning Python for the first time inside the Jupyter/IPython Notebook. And in my experience it can be very difficult for beginners to understand the connection between what's happening in the notebook ("it's in the web-browser--what does that have to do with anything on my computer??") and the underlying Python interpreter, file system, etc. Being able to pip install from within the Notebook would be a big win. This is already possible since IPython allows running system commands and it is possible to run the pip executable from the notebook, then manually restart the Jupyter kernel.
It's not 100% clear to me how my proposal below would work within a Jupyter Notebook, so that would also be an angle worth looking into.
I'm -1 on this as I view it as a tooling issue, not a language issue. If you're teaching in an environment where you don't want to instruct on the differences between the REPL and a command prompt, then that suggests to me that the environment you're presenting students needs to be different rather than asking Python to work around your teaching environment (remember, any time you ask for a change in Python you're asking the change to be applied to literally millions of developers). I also wouldn't want to tie Python-the-language to pip-the-tool so tightly. While we may make sure that pip is available for convenience, Python as a language is not dependent on pip being installed in order to function. Adding something that shells out to pip wouldn't suddenly change that relationship between language and tool. -Brett
Best, Erik
One thing that has been a step in the right direction is moving more documentation toward preferring running `python -m pip` over just `pip`, since this often has a better guarantee of running `pip` in the Python interpreter you intended. But that still requires one to know how to run the correct Python interpreter from the command-line (which the newbie double-clicking on IDLE may not even have a concept of...).
While I agree this is something that is important for beginners to learn (e.g. print(sys.executable) if in doubt), it *is* a high bar for many newbies just to install one or two packages from pip, which they often might need/want to do for whatever educational pursuit they're following (heck, it's pretty common even just to want to install the `requests` module, as I would never throw `urllib` at a beginner).
So while I don't think anything proposed here will work technically, I am in favor of an in-interpreter pip install functionality. Perhaps it could work something like this:
a) Allow it *only* in interactive mode: running `pip(...)` (or whatever this looks like) outside of interactive mode raises a `RuntimeError` with the appropriate documentation b) When running `pip(...)` the user is supplied with an interactive prompt explaining that since installing packages with `pip()` can result in changes to the interpreter, it is necessary to restart the interpreter after installation--give them an opportunity to cancel the action in case they have any work they need to save. If they proceed, install the new package then restart the interpreter for them. This avoids any ambiguity as to states of loaded modules before/after pip install.
From: Stephan Houben [mailto:stephanh42@gmail.com] Sent: Sunday, October 29, 2017 3:43 PM To: Alex Walters <tritium-list@sdamon.com> Cc: Python-Ideas <python-ideas@python.org> Subject: Re: [Python-ideas] install pip packages from Python prompt
Hi Alex,
2017-10-29 20:26 GMT+01:00 Alex Walters <tritium-list@sdamon.com>:
return “Please run pip from your system command prompt”
The target audience for my proposal are people who do not know
which part of the sheep the "system command prompt" is.
Stephan
From: Python-ideas [mailto:python-ideas-bounces+tritium-list=sdamon.com@python.org] On Behalf Of Stephan Houben Sent: Sunday, October 29, 2017 3:19 PM To: Python-Ideas <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 https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/