tqdm/tqdm

AttributeError Exception under a console-less PyInstaller build

rlaphoenix opened this issue · 0 comments

  • I have marked all applicable categories:
    • exception-raising bug
    • visual output bug
  • I have visited the source website, and in particular
    read the known issues
  • I have searched through the issue tracker for duplicates
  • I have mentioned version numbers, operating system and
    environment, where applicable:
    import tqdm, sys
    print(tqdm.__version__, sys.version, sys.platform)

Environment: 4.66.1 3.11.6 (tags/v3.11.6:8b6ee5b, Oct  2 2023, 14:57:12) [MSC v.1935 64 bit (AMD64)] win32

It seems tqdm does not support PyInstaller under a console-less window (-w flag). It is supported if you allow PyInstaller to include and show the console (-c flag). This may or may not be exclusive to PyInstaller 6.x, but that's what I'm currently using.

To reproduce take the following script:

from tqdm import tqdm

t = tqdm(total=100)
t.update(100)

print("Finished")

Run that in a normal Python interpreter environment and it runs just fine. However, freeze it with PyInstaller with -w flag (window-only flag) then it will fail. Freezing it with -c flag (include console flag) then it will work.

  File "tqdm\std.py", line 1099, in __init__
  File "tqdm\std.py", line 1348, in refresh
  File "tqdm\std.py", line 1496, in display
  File "tqdm\std.py", line 462, in print_status
  File "tqdm\std.py", line 455, in fp_write
  File "tqdm\utils.py", line 139, in __getattr__
AttributeError: 'NoneType' object has no attribute 'write'

The bug seems to occur when trying to print the status to fp where fp is None at this point:

fp.write(str(s))