verigak / progress

Easy to use progress bars for Python
ISC License
1.41k stars 179 forks source link

AttributeError: 'NoneType' object has no attribute 'isatty' #46

Closed shivareddyiirs closed 6 years ago

shivareddyiirs commented 6 years ago

Pip version: 9.0.1

Description:

I am trying to install pyxform package at runtime in QGIS 3. When i am running same code in cmd it runs fine. But when I runs in QGIS 3 python console it gives error.

What I've run:

import pip pip.main(['install','pyxform','--user'])

Traceback (most recent call last):
  File "C:\PROGRA~1\QGIS3~1.0\apps\Python36\lib\site-packages\pip\basecommand.py", line 215, in main
    status = self.run(options, args)
  File "C:\PROGRA~1\QGIS3~1.0\apps\Python36\lib\site-packages\pip\commands\install.py", line 335, in run
    wb.build(autobuilding=True)
  File "C:\PROGRA~1\QGIS3~1.0\apps\Python36\lib\site-packages\pip\wheel.py", line 749, in build
    self.requirement_set.prepare_files(self.finder)
  File "C:\PROGRA~1\QGIS3~1.0\apps\Python36\lib\site-packages\pip\req\req_set.py", line 380, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "C:\PROGRA~1\QGIS3~1.0\apps\Python36\lib\site-packages\pip\req\req_set.py", line 620, in _prepare_file
    session=self.session, hashes=hashes)
  File "C:\PROGRA~1\QGIS3~1.0\apps\Python36\lib\site-packages\pip\download.py", line 821, in unpack_url
    hashes=hashes
  File "C:\PROGRA~1\QGIS3~1.0\apps\Python36\lib\site-packages\pip\download.py", line 659, in unpack_http_url
    hashes)
  File "C:\PROGRA~1\QGIS3~1.0\apps\Python36\lib\site-packages\pip\download.py", line 882, in _download_http_url
    _download_url(resp, link, content_file, hashes)
  File "C:\PROGRA~1\QGIS3~1.0\apps\Python36\lib\site-packages\pip\download.py", line 585, in _download_url
    progress_indicator = DownloadProgressBar(max=total_length).iter
  File "C:\PROGRA~1\QGIS3~1.0\apps\Python36\lib\site-packages\pip\utils\ui.py", line 158, in __init__
    super(WindowsMixin, self).__init__(*args, **kwargs)
  File "C:\PROGRA~1\QGIS3~1.0\apps\Python36\lib\site-packages\pip\utils\ui.py", line 82, in __init__
    super(InterruptibleMixin, self).__init__(*args, **kwargs)
  File "C:\PROGRA~1\QGIS3~1.0\apps\Python36\lib\site-packages\pip\utils\ui.py", line 118, in __init__
    super(DownloadProgressMixin, self).__init__(*args, **kwargs)
  File "C:\PROGRA~1\QGIS3~1.0\apps\Python36\lib\site-packages\pip\_vendor\progress\helpers.py", line 58, in __init__
    if self.file.isatty() and self.hide_cursor:
AttributeError: 'NoneType' object has no attribute 'isatty'
verigak commented 6 years ago

It looks like under QGIS sys.stderr is None. I added a check for this case, thanks!

shivareddyiirs commented 6 years ago

Thanks @verigak but issue is still not resolved. After updating above I get following error:

Collecting https://github.com/XLSForm/pyxform/archive/master.zip
  Downloading https://github.com/XLSForm/pyxform/archive/master.zip (1.7MB)
Exception:
Traceback (most recent call last):
  File "C:\PROGRA~1\QGIS3~1.0\apps\Python36\lib\site-packages\pip\basecommand.py", line 215, in main
    status = self.run(options, args)
  File "C:\PROGRA~1\QGIS3~1.0\apps\Python36\lib\site-packages\pip\commands\install.py", line 335, in run
    wb.build(autobuilding=True)
  File "C:\PROGRA~1\QGIS3~1.0\apps\Python36\lib\site-packages\pip\wheel.py", line 749, in build
    self.requirement_set.prepare_files(self.finder)
  File "C:\PROGRA~1\QGIS3~1.0\apps\Python36\lib\site-packages\pip\req\req_set.py", line 380, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "C:\PROGRA~1\QGIS3~1.0\apps\Python36\lib\site-packages\pip\req\req_set.py", line 620, in _prepare_file
    session=self.session, hashes=hashes)
  File "C:\PROGRA~1\QGIS3~1.0\apps\Python36\lib\site-packages\pip\download.py", line 821, in unpack_url
    hashes=hashes
  File "C:\PROGRA~1\QGIS3~1.0\apps\Python36\lib\site-packages\pip\download.py", line 659, in unpack_http_url
    hashes)
  File "C:\PROGRA~1\QGIS3~1.0\apps\Python36\lib\site-packages\pip\download.py", line 882, in _download_http_url
    _download_url(resp, link, content_file, hashes)
  File "C:\PROGRA~1\QGIS3~1.0\apps\Python36\lib\site-packages\pip\download.py", line 605, in _download_url
    consume(downloaded_chunks)
  File "C:\PROGRA~1\QGIS3~1.0\apps\Python36\lib\site-packages\pip\utils\__init__.py", line 852, in consume
    deque(iterator, maxlen=0)
  File "C:\PROGRA~1\QGIS3~1.0\apps\Python36\lib\site-packages\pip\download.py", line 571, in written_chunks
    for chunk in chunks:
  File "C:\PROGRA~1\QGIS3~1.0\apps\Python36\lib\site-packages\pip\utils\ui.py", line 141, in iter
    self.next(n)
  File "C:\PROGRA~1\QGIS3~1.0\apps\Python36\lib\site-packages\pip\_vendor\progress\__init__.py", line 73, in next
    self.update()
  File "C:\PROGRA~1\QGIS3~1.0\apps\Python36\lib\site-packages\pip\_vendor\progress\bar.py", line 41, in update
    self.writeln(line)
  File "C:\PROGRA~1\QGIS3~1.0\apps\Python36\lib\site-packages\pip\_vendor\progress\helpers.py", line 66, in writeln
    if self.file and self.file.isatty():
  File "C:\PROGRA~1\QGIS3~1.0\apps\Python36\lib\site-packages\pip\utils\ui.py", line 167, in <lambda>
    self.file.isatty = lambda: self.file.wrapped.isatty()
AttributeError: 'NoneType' object has no attribute 'isatty'
2
verigak commented 6 years ago

This looks like it is happening in pip. pip is essentially running:

self.file = sys.stdout
if WINDOWS and colorama:
    self.file = colorama.AnsiToWin32(self.file)
    self.file.isatty = lambda: self.file.wrapped.isatty()

But in the case of QGIS it looks like sys.stdout is None, so self.file becomes None and then self.file.wrapped becomes None.