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: Improve error message for OS command entered at >>> prompt
Type: enhancement Stage: resolved
Components: Versions: Python 3.11
process
Status: closed Resolution: duplicate
Dependencies: Superseder: Give better errors for OS commands, like 'pip', in REPL, script
View: 28140
Assigned To: Nosy List: AlexWaygood, aroberge, pablogsal, steven.daprano, terry.reedy
Priority: normal Keywords:

Created on 2021-11-05 01:53 by steven.daprano, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (4)
msg405764 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2021-11-05 01:53
A frequent newbie mistake is to call shell commands from inside the interactive interpreter. Most common is to call Python itself.

Here is an example where a Python instructor was allegedly unable to diagnose the issue for their students:

https://windowsquestions.com/2021/10/09/syntaxerror-invalid-syntax-perhaps-you-forgot-a-comma/


I think it would be a nice feature if the compiler recognised obvious cases of "user tried to call Python from the Python prompt", and suggested a fix. If the statement matches the regex r"python\s+" the error message might say "it looks like you are trying to run a shell command at the Python prompt" rather than suggest a missing comma.
msg405774 - (view) Author: Andre Roberge (aroberge) * Date: 2021-11-05 09:43
I think that "trying to run a shell command" might not be easy to understand by a beginner.

If the special case of r"python\s+" is added, perhaps r"pip\s+" should be considered as well since many sites on the Internet suggest to install packages using "pip install ..." instead of "python -m pip install ..."
msg405787 - (view) Author: Alex Waygood (AlexWaygood) * (Python triager) Date: 2021-11-05 11:41
+1 for adding r"pip\s" as a special case as well. A few months ago, I was trying to (remotely) help a beginner friend debug why his attempt to install a library wasn't working. It took me ages before I realised he was entering it into the interactive REPL rather than a terminal window.
msg405841 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2021-11-06 01:53
Agreed. 'pip ...' not working is a recurring question on stackoverflow, usually from an IDLE user.  'python' is much rarer.  Note that IDLE's shell may be a beginner's only exposure to the word 'shell'.  The standard Windows shell is the Command Prompt console, so one has to say 'Command Prompt command'.  Would 'bash command' work elsewhere?
History
Date User Action Args
2022-04-11 14:59:52adminsetgithub: 89884
2021-11-28 16:53:49terry.reedysetstatus: open -> closed
superseder: Give better errors for OS commands, like 'pip', in REPL, script
resolution: duplicate
stage: resolved
2021-11-06 01:53:58terry.reedysetnosy: + pablogsal, terry.reedy

messages: + msg405841
title: Improve error message when python shell command is entered at the REPL prompt -> Improve error message for OS command entered at >>> prompt
2021-11-05 11:41:52AlexWaygoodsetnosy: + AlexWaygood
messages: + msg405787
2021-11-05 09:43:25arobergesetnosy: + aroberge
messages: + msg405774
2021-11-05 01:53:40steven.dapranocreate