msg276373 - (view) |
Author: Alyssa Coghlan (ncoghlan) *  |
Date: 2016-09-14 04:40 |
A problem we're starting to see on distutils-sig is folks trying to type pip commands into the Python REPL rather than their system shell, and getting cryptic syntax errors back: >>> pip install requests File "", line 1 pip install requests ^ SyntaxError: invalid syntax >>> python -m pip install requests File "", line 1 python -m pip install requests ^ SyntaxError: invalid syntax This may be amenable to a similar solution to the one we used to give a custom error message for "print ": >>> print foo File "", line 1 print foo ^ SyntaxError: Missing parentheses in call to 'print' That code currently checks for "print " and "exec ", so it would be a matter of adding another special case that looked for "pip install " appearing anywhere in the string that's failing to compile (it can't be limited to the start as it may be an attempt to invoke pip via "-m") |
|
|
msg276506 - (view) |
Author: Alyssa Coghlan (ncoghlan) *  |
Date: 2016-09-15 03:24 |
Paul Moore pointed out on distutils-sig that since this is mainly desired for the REPL, we can put the logic in the default excepthook rather than into the SyntaxError constructor the way we had to for "print" and "exec": def excepthook(typ, value, traceback): if typ is SyntaxError and "pip install" in value.text: print("'pip install' found in supplied text") print("Try running this from a system command prompt") return sys.__excepthook__(typ, value, traceback) |
|
|
msg276510 - (view) |
Author: Alyssa Coghlan (ncoghlan) *  |
Date: 2016-09-15 03:33 |
Given that this can be done with just an excepthook change, I'm going to suggest we make the change for 3.5 and 2.7 as well. |
|
|
msg322565 - (view) |
Author: Tom Viner (tomviner) * |
Date: 2018-07-28 15:03 |
I am looking at this, as part of the EuroPython 2018 sprint. |
|
|
msg407201 - (view) |
Author: Irit Katriel (iritkatriel) *  |
Date: 2021-11-28 12:22 |
On 3.11: >>> pip install requests File "", line 1 pip install requests ^^^^^^^^^^^ SyntaxError: invalid syntax. Perhaps you forgot a comma? |
|
|
msg407202 - (view) |
Author: Alex Waygood (AlexWaygood) *  |
Date: 2021-11-28 12:25 |
Similar discussion in a newer issue: https://bugs.python.org/issue45721 |
|
|
msg407213 - (view) |
Author: Terry J. Reedy (terry.reedy) *  |
Date: 2021-11-28 17:39 |
I closed #45721, which has additional comments, as a duplicate of this. 'print foo' now results in "SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?" |
|
|
msg407226 - (view) |
Author: Tom Viner (tomviner) * |
Date: 2021-11-28 19:44 |
I've updated my pull request from 3 years ago. Fixed merge conflicts and addressed all comments. https://github.com/python/cpython/pull/8536 |
|
|