On 15 September 2016 at 01:31, Paul Moore <[email protected]> wrote:
> On 13 September 2016 at 23:55, Donald Stufft <[email protected]> wrote:
>> Perhaps a better idea would be to add some smarts to the REPL (but not to 
>> Python itself) that would detect something like:
>>
>>>>> pip install
>>
>> And print a better error message that gives a better indication about what’s 
>> gone wrong besides a SyntaxError?
>
> This is pretty easy to do:
>
> def excepthook(typ, value, traceback):
>     # Tidy this up to suit
>     if typ is SyntaxError and value.text.startswith("pip"):
>         print("You may want to run this from a shell prompt")
>         return
>     sys.__excepthook__(typ, value, traceback)
>
> sys.excepthook = excepthook

Good point, now noted at http://bugs.python.org/issue28140#msg276506

> Of course, it doesn't solve the problem of a user who doesn't know
> what a "shell prompt" is...

As Thomas suggested, even though *we* use "shell" specifically for the
system shell, and "REPL" for the interactive prompt, something like
"system command prompt" is likely the better phrase, since the REPL
does get referred to as a "Python shell" fairly often, including by
IDLE.

Plugging "system command prompt" into Google doesn't give helpful
results, though.

An unqualified "command prompt" is better, as searching for that gives
generic Windows command line access instructions, while qualifying it
with "command prompt mac os x" gives Mac instructions and "command
prompt linux" gives decent Linux instructions.

As far as the error message goes, what I'd suggest is:

1. detect "pip install" specifically (anywhere in the line), not just "pip"
2. report what triggered the custom recommendation in addition to the
recommendation itself

For example:

    >>> python –m pip install Numpy
    SyntaxError: 'pip install' is a command line operation
    Try running this at a command prompt rather than from Python

Once the pip bundled via ensurepip gains "pip.install()" support
(assuming we end up doing that), then the custom message can change
to:

    >>> python –m pip install Numpy
    SyntaxError: 'pip install' is a command line operation
    Try running this at a command prompt rather than from Python, or else try:

        import pip
        pip.install("NumPy")

Regards,
Nick.

-- 
Nick Coghlan   |   [email protected]   |   Brisbane, Australia
_______________________________________________
Distutils-SIG maillist  -  [email protected]
https://mail.python.org/mailman/listinfo/distutils-sig

Reply via email to