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

AttributeError: 'NoneType' object has no attribute 'flush' #24047

Closed
4 tasks
akesh1235 opened this issue Jun 6, 2023 · 5 comments · Fixed by #25033
Closed
4 tasks

AttributeError: 'NoneType' object has no attribute 'flush' #24047

akesh1235 opened this issue Jun 6, 2023 · 5 comments · Fixed by #25033

Comments

@akesh1235
Copy link

akesh1235 commented Jun 6, 2023

System Info

System info

  • transformers version: 4.29.2
  • Platform: Windows-10-10.0.19045-SP0
  • Python version: 3.11.3
  • Huggingface_hub version: 0.15.1
  • Safetensors version: not installed
  • PyTorch version (GPU?): not installed (NA)
  • Tensorflow version (GPU?): not installed (NA)
  • Flax version (CPU?/GPU?/TPU?): not installed (NA)
  • Jax version: not installed
  • JaxLib version: not installed
  • Using GPU in script?: No
  • Using distributed or parallel set-up in script?:

Issue

**After creating virtual environment and installing requirements.txt, carried out following steps to convert .py file into .exe ** using pyinstaller library

step 1 : pip install pyinstaller
step 2 : pyinstaller --name GrammarCorrector --onefile --windowed new_gram1_Tkinter.py --hidden-import cymem.cymem

Then i got this AttributeError:
Traceback (most recent call last):
File "new_gram1_Tkinter.py", line 271, in
File "new_gram1_Tkinter.py", line 142, in init
File "", line 1007, in _find_and_load
File "", line 986, in _find_and_load_unlocked
File "", line 680, in load_unlocked
File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module
File "transformers_init
.py", line 26, in
File "", line 1007, in _find_and_load
File "", line 986, in _find_and_load_unlocked
File "", line 680, in _load_unlocked
File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module
File "transformers\dependency_versions_check.py", line 17, in
File "", line 1007, in _find_and_load
File "", line 986, in _find_and_load_unlocked
File "", line 680, in load_unlocked
File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module
File "transformers\utils_init
.py", line 30, in
File "", line 1007, in _find_and_load
File "", line 986, in _find_and_load_unlocked
File "", line 680, in _load_unlocked
File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module
File "transformers\utils\generic.py", line 29, in
File "", line 1007, in _find_and_load
File "", line 986, in _find_and_load_unlocked
File "", line 680, in _load_unlocked
File "PyInstaller\loader\pyimod02_importers.py", line 352, in exec_module
File "transformers\utils\import_utils.py", line 36, in
File "transformers\utils\logging.py", line 124, in get_logger
File "transformers\utils\logging.py", line 88, in _configure_library_root_logger

AttributeError: 'NoneType' object has no attribute 'flush'

I raised issue in pyinstaller repository, and i got answer as followed below from @bwoodsend who is a maintainer

You should be able to get the same error without PyInstaller if you run your source code using pythonw instead of just python. Raise a bug to transformers if they have their own windowed-mode-naive logger. https://github.com/orgs/pyinstaller/discussions/7689#discussion-5270292

Who can help?

@sgugger
@ArthurZucker
@LysandreJik

Information

  • The official example scripts
  • My own modified scripts

Tasks

  • An officially supported task in the examples folder (such as GLUE/SQuAD, ...)
  • My own task or dataset (give details below)

Reproduction

I want my .py file in .exe file and when i am doing that using pyinstaller it is giving Attribute error when i asked pyinstaller developers on repository they suggested me to raise bug report on transformers saying that if they have their own windowed-mode-naive logger.

Expected behavior

i want .exe file from .py

@sgugger
Copy link
Collaborator

sgugger commented Jun 6, 2023

cc @LysandreJik maybe

@17Reset
Copy link

17Reset commented Jun 25, 2023

Hello, I have encountered the same problem as you, did you solve it?

@sabaimran
Copy link

Hi! I also encountered this error. I'm building a package with pyinstaller which works on MacOS with M2 amd64. Running inside of a Windows VM running Windows 11, this fails with the same error.

File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 385, in exec_module
  File "transformers\utils\import_utils.py", line 37, in <module>
    logger = logging.get_logger(__name__)  # pylint: disable=invalid-name
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "transformers\utils\logging.py", line 124, in get_logger
    _configure_library_root_logger()
  File "transformers\utils\logging.py", line 88, in _configure_library_root_logger
    _default_handler.flush = sys.stderr.flush
                             ^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'flush'

@17Reset
Copy link

17Reset commented Jul 14, 2023

你好!我也遇到了这个错误。我正在构建一个在 MacOS 上使用 M2 amd64 的软件包。在运行 Windows 11 的 Windows VM 中运行,此操作失败并出现相同的错误。pyinstaller

File "<frozen importlib._bootstrap>", line 1176, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1147, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "PyInstaller\loader\pyimod02_importers.py", line 385, in exec_module
  File "transformers\utils\import_utils.py", line 37, in <module>
    logger = logging.get_logger(__name__)  # pylint: disable=invalid-name
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "transformers\utils\logging.py", line 124, in get_logger
    _configure_library_root_logger()
  File "transformers\utils\logging.py", line 88, in _configure_library_root_logger
    _default_handler.flush = sys.stderr.flush
                             ^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'flush'

You can add this code before your transformers import
if sys.stdout is None:
sys.stdout = open(os.devnull, "w")
if sys.stderr is None:
sys.stderr = open(os.devnull, "w")

@Giadissima
Copy link

if by chance you have this error and you have a Virtualenv, remember to generate the pyinstaller exe from inside the virtual environment, I solved it like this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants