-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
gh-72327: Suggest using system terminal for pip install in PyREPL #136328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
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. Co-authored-by: Tom Viner <tom@viner.tv> Co-authored-by: Brian Schubert <brianm.schubert@gmail.com>
The new REPL has a similar special case for when cpython/Lib/_pyrepl/console.py Lines 210 to 217 in 1953713
Maybe this could be done in a similar way? Something like this might work: :...skipping...
diff --git a/Lib/_pyrepl/console.py b/Lib/_pyrepl/console.py
index 8956fb1242e..833e79ef3c2 100644
--- a/Lib/_pyrepl/console.py
+++ b/Lib/_pyrepl/console.py
@@ -195,7 +195,15 @@ def runsource(self, source, filename="<input>", symbol="single"):
ast.PyCF_ONLY_AST,
incomplete_input=False,
)
- except (SyntaxError, OverflowError, ValueError):
+ except SyntaxError as e:
+ if "pip install" in source: # maybe use a more general regex?
+ e.add_note(
+ "Did you mean to run the 'pip' command?."
+ " If so, <insert tip message here>"
+ )
+ self.showsyntaxerror(filename, source=source)
+ return False
+ except (OverflowError, ValueError):
self.showsyntaxerror(filename, source=source)
return False
if tree.body: |
I teach Python at the university level, and this is a pretty common issue, so I think this would be a good addition! Maybe checking if I feel like this might want to be a more specific check, like matching the source string against something like |
Ah crap, I forgot that force-pushing is frown upon here. Sorry about that! @brianschubert thanks for the suggestion. Implementing this via the new REPL is much cleaner! I've updated my patch to use your approach. |
It may be nice to include "or pip3" depending on which version they want to use. |
I really don't want to get into the weeds of how to invoke pip (because the answer is "it depends" and I don't want to make this more complicated). The point of saying "try the 'pip' command" is that it can't simply be copied. The onus is on the user to invoke pip appropriately for their system. In most cases, I expect them to re-copy and paste what they just pasted/typed in. |
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
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. The pip project still receives the occasional issue from users lamenting that "pip is not working!" (pypa/pip#13409)This is an updated version of #8536.
cc @ncoghlan