mirror of
https://github.com/python/cpython.git
synced 2025-11-02 14:41:33 +00:00
gh-72327: Suggest using system terminal for pip install in PyREPL (#136328)
Users new to Python packaging often try to use pip from the REPL only to be met with a confusing SyntaxError. If this happens, guide the user to use a system terminal instead to invoke pip. Closes #72327 --------- Co-authored-by: Tom Viner <tom@viner.tv> Co-authored-by: Brian Schubert <brianm.schubert@gmail.com> Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Co-authored-by: Alyssa Coghlan <ncoghlan@gmail.com>
This commit is contained in:
parent
a8f42e6e88
commit
be02e68158
4 changed files with 29 additions and 1 deletions
|
|
@ -27,6 +27,7 @@
|
|||
import linecache
|
||||
from dataclasses import dataclass, field
|
||||
import os.path
|
||||
import re
|
||||
import sys
|
||||
|
||||
|
||||
|
|
@ -195,7 +196,19 @@ def runsource(self, source, filename="<input>", symbol="single"):
|
|||
ast.PyCF_ONLY_AST,
|
||||
incomplete_input=False,
|
||||
)
|
||||
except (SyntaxError, OverflowError, ValueError):
|
||||
except SyntaxError as e:
|
||||
# If it looks like pip install was entered (a common beginner
|
||||
# mistake), provide a hint to use the system command prompt.
|
||||
if re.match(r"^\s*(pip3?|py(thon3?)? -m pip) install.*", source):
|
||||
e.add_note(
|
||||
"The Python package manager (pip) can only be used"
|
||||
" outside of the Python REPL.\n"
|
||||
"Try the 'pip' command in a separate terminal or"
|
||||
" command prompt."
|
||||
)
|
||||
self.showsyntaxerror(filename, source=source)
|
||||
return False
|
||||
except (OverflowError, ValueError):
|
||||
self.showsyntaxerror(filename, source=source)
|
||||
return False
|
||||
if tree.body:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue