Skip to content

2.0.0 sys.stderr attribute error packaged with cx_freeze #26862

Closed

Description

@jonnypeace

Describe the issue:

I have tested by only upgrading to 2.0.0 with numpy, and noticed the package build with cx freeze would be successful, until I tried to open the executable, and I would receive this window pop up.

Version 1.26.4 would package fine with cx_freeze and I've not upgrade cx_freeze.

If I have more time at the end of my day I will trek through some of the files and see if sys.stderr is modified anywhere in your code.

Sorry for the short code block below, it happens on launch.

Reproduce the code example:

import numpy as np

Error message:

cx_Freeze: Python error in main script

Traceback (most recent call last):
  File "CENSORED/lib/site-packages/cx_Freeze/initscripts/__startup__.py", line 141, in run
    module.run(name + "__main__")
  File "CENSORED/lib/site-packages/cx_Freeze/initscripts/Console.py", line 25, in run
    exec(code, __main__.__dict__)
  File "output_data.py", line 2, in <module>
  File "CENSORED/reproducibility.py", line 6, in <module>
    from .interpolate import PchipInterpolator
  File "CENSORED/interpolate/__init__.py", line 167, in <module>
  File "CENSORED/interpolate/interpolate.py", line 10, in <module>
    import scipy.special as spec
  File "CENSORED/special/__init__.py", line 811, in <module>
  File "CENSORED/special/_ufuncs.py", line 7, in <module>
  File "CENSORED/_lib/_uarray/_uarray_dispatch.cpython-38-x86_64-linux-gnu.so", line 21, in init _lib._uarray
  File "CENSORED/__init__.py", line 19, in <module>
    from . import _typeconv
  File "CENSORED/_typeconv.py", line 23, in <module>
    from . import _nd_image
  File "CENSORED/_nd_image.py", line 159, in <module>
    from . import _ni_support
  File "CENSORED/_ni_support.py", line 19, in <module>
    from . import _numpy_compat
  File "CENSORED/_numpy_compat.py", line 19, in <module>
    from . import _pocketfft_internal
  File "CENSORED/_pocketfft_internal.py", line 19, in <module>
    from . import _spectral
  File "CENSORED/_spectral.py", line 19, in <module>
    errmess = sys.stderr.write
AttributeError: 'NoneType' object has no attribute 'write'

Python and NumPy Versions:

2.0.0

Runtime Environment:

Using a package build with cx freeze, on windows 10. Cx freeze is version 7.1.1

Context for the issue:

I can use 1.26.4, I just noticed this bug during a package build using 2.0.0. I realise 2.0.0 is a major release, and if stderr is potentially a None on import, then it might be worth looking at.

Activity

  1. seberg commented on Jul 6, 2024

    @seberg
    Member

    I really don't see anything here related to NumPy (numpy isn't in the stacktrace, numpy has nothing to do with sys.stderr, ...). If it really has to do with the NumPy version as you say, I half expect that installing/uninstalling it just changed other versions as well.

    Going to close this for now, if you can get a better idea of why NumPy is involved, please post and we can reopen.

  2. jonnypeace commented on Jul 6, 2024

    @jonnypeace
    Author

    I did have time to check the previous version, which had a utils.py, which reassigned sys.stderr, but in 2.0.0, that file doesn't seem to exist... I think. I will have a look further when I get time, thanks for getting back.

  3. nicoddemus commented on Jul 22, 2024

    @nicoddemus
    Contributor

    Hi folks,

    I'm seeing the same problem, here is the traceback I'm getting:

      File "numpy\f2py\auxfuncs.py", line 19, in <module>
      File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
      File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
      File "PyInstaller\loader\pyimod02_importers.py", line 419, in exec_module
      File "numpy\f2py\cfuncs.py", line 19, in <module>
    AttributeError: 'NoneType' object has no attribute 'write'

    Here is the line that crashes:

    errmess = sys.stderr.write

    When frozen without a console (common in GUI applications), sys.stderr and sys.stdout are both None.

    I'm seeing this crash both in 2.0.0 and 2.0.1.

  4. added a commit that references this issue on Jul 22, 2024
    3887aaf
  5. added a commit that references this issue on Jul 24, 2024
    e10db14
  6. added a commit that references this issue on Nov 1, 2024
    2de3532
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions