Skip to content
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

crash when sys.stdin is None in #7119

emilburzo opened this issue Sep 30, 2019 · 2 comments · Fixed by #7118

crash when sys.stdin is None in #7119

emilburzo opened this issue Sep 30, 2019 · 2 comments · Fixed by #7118


Copy link

@emilburzo emilburzo commented Sep 30, 2019


  • pip version: 19.2.3
  • Python version: 3.7.4
  • OS: archlinux


The code that determines if to use interactive mode in breaks when sys.stdin is None

Expected behavior

Does not crash.

How to Reproduce

(On linux)

  1. Run: virtualenv -p python3 env
  2. Run: source env/bin/activate
  3. Run: python -c 'import pip._internal as pip' 0<&- (this simulates a None sys.stdin)


$ virtualenv -p python3 env
Running virtualenv with interpreter /usr/bin/python3
Using base prefix '/usr'
New python executable in /tmp/env/bin/python3
Also creating executable in /tmp/env/bin/python
Installing setuptools, pip, wheel...
$ source env/bin/activate
(env) $ python -c 'import pip._internal as pip' 0<&-
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/tmp/env/lib/python3.7/site-packages/pip/_internal/", line 40, in <module>
    from pip._internal.cli.autocompletion import autocomplete
  File "/tmp/env/lib/python3.7/site-packages/pip/_internal/cli/", line 8, in <module>
    from pip._internal.cli.main_parser import create_main_parser
  File "/tmp/env/lib/python3.7/site-packages/pip/_internal/cli/", line 11, in <module>
    from pip._internal.commands import (
  File "/tmp/env/lib/python3.7/site-packages/pip/_internal/commands/", line 6, in <module>
    from pip._internal.commands.completion import CompletionCommand
  File "/tmp/env/lib/python3.7/site-packages/pip/_internal/commands/", line 6, in <module>
    from pip._internal.cli.base_command import Command
  File "/tmp/env/lib/python3.7/site-packages/pip/_internal/cli/", line 21, in <module>
    from import PipSession
  File "/tmp/env/lib/python3.7/site-packages/pip/_internal/", line 47, in <module>
    from pip._internal.vcs import vcs
  File "/tmp/env/lib/python3.7/site-packages/pip/_internal/vcs/", line 12, in <module>
    import pip._internal.vcs.subversion  # noqa: F401
  File "/tmp/env/lib/python3.7/site-packages/pip/_internal/vcs/", line 314, in <module>
  File "/tmp/env/lib/python3.7/site-packages/pip/_internal/vcs/", line 165, in register
    self._registry[] = cls()
  File "/tmp/env/lib/python3.7/site-packages/pip/_internal/vcs/", line 180, in __init__
    use_interactive = sys.stdin.isatty()
AttributeError: 'NoneType' object has no attribute 'isatty'
(env) $ 


And in case you're wondering how I got to this internal API: I'm running (on AWS Lambda) awslimitchecker, which uses versionfinder, which uses pip

Copy link

@pfmoore pfmoore commented Sep 30, 2019

Have you reported the incorrect usage of pip's internals to the offending project(s)? They should fix their code. Also, the python docs don't seem to indicate that None is a valid value for sys.stdin. Experimentally, it seems like it's possible though:

[vagrant@localhost ~]$ python3 -V
Python 3.7.0
[vagrant@localhost ~]$ python3 -c 'import sys; print(repr(sys.stdin))' 0<&-

Having said that, the fix seems relatively harmless so I have no real objection to adding a bit of defensive code to pip.

Copy link

@pradyunsg pradyunsg commented Sep 30, 2019

FWIW, python src/pip install --upgrade pip 0<&- on master, also crashes the same way and the proposed patch fixes it. :)

@lock lock bot added the S: auto-locked label Nov 1, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Nov 1, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants