-
-
Notifications
You must be signed in to change notification settings - Fork 33.6k
gh-72327: Add help message for pip in REPL #8536
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
Changes from 7 commits
1e02cdb
49a8299
b762543
0784d5a
ab29fa1
5bb0a8d
239fd5d
2d302e6
ae30adf
2bb1e38
f9bb5c8
e092342
0e6d9e2
8122a6e
2cd4867
5034571
36c8256
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -390,6 +390,23 @@ def setcopyright(): | |
| files, dirs) | ||
|
|
||
|
|
||
| def _register_detect_pip_usage_in_repl(): | ||
| old_excepthook = sys.excepthook | ||
|
|
||
| def detect_pip_usage_in_repl(typ, value, traceback): | ||
| if typ is SyntaxError and ( | ||
| "pip install" in value.text or "pip3 install" in value.text | ||
| ): | ||
| value.msg = ("The Python package manager (pip) can only be used" | ||
|
||
| " from outside of Python.\n" | ||
| "Please try the `pip` command in a" | ||
| " separate terminal or command prompt.") | ||
|
|
||
| old_excepthook(typ, value, traceback) | ||
|
|
||
| sys.excepthook = detect_pip_usage_in_repl | ||
serhiy-storchaka marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| def sethelper(): | ||
| builtins.help = _sitebuiltins._Helper() | ||
|
|
||
|
|
@@ -558,6 +575,12 @@ def main(): | |
| setquit() | ||
| setcopyright() | ||
| sethelper() | ||
| # Detect REPL by prompt, -i flag or PYTHONINSPECT env var being set. | ||
serhiy-storchaka marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if ( | ||
| hasattr(sys, 'ps1') or sys.flags.interactive or | ||
| os.environ.get('PYTHONINSPECT') | ||
| ): | ||
serhiy-storchaka marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| _register_detect_pip_usage_in_repl() | ||
terryjreedy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if not sys.flags.isolated: | ||
| enablerlcompleter() | ||
| execsitecustomize() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Give better errors for ``pip install`` command typed into the REPL. Patch by | ||
| Tom Viner. |
Uh oh!
There was an error while loading. Please reload this page.