homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Give better errors for OS commands, like 'pip', in REPL, script
Type: enhancement Stage: patch review
Components: Interpreter Core Versions: Python 3.11
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: AlexWaygood, aroberge, iritkatriel, ncoghlan, pablogsal, steven.daprano, terry.reedy, tomviner, yselivanov
Priority: normal Keywords: patch

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 "<stdin>", line 1
 pip install requests
 ^
SyntaxError: invalid syntax
>>> python -m pip install requests
 File "<stdin>", 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 "<stdin>", 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 "<stdin>", 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:36adminsetgithub: 72327
2021年11月28日 19:44:25tomvinersetmessages: + msg407226
2021年11月28日 17:39:04terry.reedysettitle: Attempt to give better errors for pip commands typed into the REPL -> Give better errors for OS commands, like 'pip', in REPL, script
nosy: + aroberge

messages: + msg407213

components: + Interpreter Core
2021年11月28日 16:53:49terry.reedylinkissue45721 superseder
2021年11月28日 12:25:20AlexWaygoodsetnosy: + AlexWaygood, terry.reedy, steven.daprano, pablogsal
messages: + msg407202
2021年11月28日 12:22:11iritkatrielsetnosy: + iritkatriel

messages: + msg407201
versions: + Python 3.11, - Python 2.7, Python 3.5, Python 3.6, Python 3.7
2018年07月28日 16:45:26tomvinersetkeywords: + patch
stage: patch review
pull_requests: + pull_request8053
2018年07月28日 15:03:50tomvinersetmessages: + msg322565
2017年11月06日 16:24:33vstinnersetnosy: + yselivanov
2017年11月05日 22:23:24tomvinersetnosy: + tomviner
2016年09月15日 03:33:10ncoghlansetmessages: + msg276510
versions: + Python 2.7, Python 3.5
2016年09月15日 03:24:24ncoghlansetmessages: + msg276506
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:03ncoghlancreate

AltStyle によって変換されたページ (->オリジナル) /