Issue 28140: Give better errors for OS commands, like 'pip', in REPL, script (original) (raw)

Created on 2016-09-14 04:40 by ncoghlan, last changed 2022-04-11 14:58 by admin.

Pull Requests
URL Status Linked Edit
PR 8536 open tomviner,2018-07-28 16:45
Messages (8)
msg276373 - (view) Author: Alyssa Coghlan (ncoghlan) * (Python committer) 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) * (Python committer) 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) * (Python committer) 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) * (Python committer) 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) * (Python triager) 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) * (Python committer) 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
History
Date User Action Args
2022-04-11 14:58:36 admin set github: 72327
2021-11-28 19:44:25 tomviner set messages: +
2021-11-28 17:39:04 terry.reedy set title: Attempt to give better errors for pip commands typed into the REPL -> Give better errors for OS commands, like 'pip', in REPL, scriptnosy: + arobergemessages: + components: + Interpreter Core
2021-11-28 16:53:49 terry.reedy link issue45721 superseder
2021-11-28 12:25:20 AlexWaygood set nosy: + AlexWaygood, terry.reedy, steven.daprano, pablogsalmessages: +
2021-11-28 12:22:11 iritkatriel set nosy: + iritkatrielmessages: + versions: + Python 3.11, - Python 2.7, Python 3.5, Python 3.6, Python 3.7
2018-07-28 16:45:26 tomviner set keywords: + patchstage: patch reviewpull_requests: + <pull%5Frequest8053>
2018-07-28 15:03:50 tomviner set messages: +
2017-11-06 16:24:33 vstinner set nosy: + yselivanov
2017-11-05 22:23:24 tomviner set nosy: + tomviner
2016-09-15 03:33:10 ncoghlan set messages: + versions: + Python 2.7, Python 3.5
2016-09-15 03:24:24 ncoghlan set messages: + title: Attempt to give better errors for shell commands typed into the REPL -> Attempt to give better errors for pip commands typed into the REPL
2016-09-14 04:40:03 ncoghlan create