Skip to content

ImportError when attempting to test with Python 3.14 #302

Closed

Description

@befeleme

Trying to run the tests with Python 3.14, I run into ImportError. This is new, doesn't happen with Python 3.13.
I test with Python 3.14, because I prepare an update of the main Python in Fedora Linux 43 and try to rebuild all Python packages as such.

$ tox -e py314
py314: commands[0]> pytest --cov=lz4/block --cov=lz4/frame --tb=long tests/block tests/frame
ImportError while loading conftest '/home/ksurma/dev/python-lz4/tests/frame/conftest.py'.
tests/frame/conftest.py:2: in <module>
    import lz4.frame as lz4frame
lz4/frame/__init__.py:30: in <module>
    from . import _compression
E   ImportError: cannot import name '_compression' from partially initialized module 'lz4.frame' (most likely due to a circular import) (/home/ksurma/dev/python-lz4/lz4/frame/__init__.py)

Or just on an installed project in Python 3.14 venv:

$ python                      
>>> import lz4.frame as lz4frame
Traceback (most recent call last):
  File "/home/ksurma/dev/python-lz4/lz4/frame/__init__.py", line 28, in <module>
    import _compression   # Python 3.6 and later
    ^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named '_compression'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<python-input-0>", line 1, in <module>
    import lz4.frame as lz4frame
  File "/home/ksurma/dev/python-lz4/lz4/frame/__init__.py", line 30, in <module>
    from . import _compression
ImportError: cannot import name '_compression' from partially initialized module 'lz4.frame' (most likely due to a circular import) (/home/ksurma/dev/python-lz4/lz4/frame/__init__.py)

Activity

  1. hroncok commented on May 29, 2025

    @hroncok

    From https://peps.python.org/pep-0784/

    The _compression module, given that it is marked private, will be immediately renamed to compression._common._streams.

    Here:

    try:
    import _compression # Python 3.6 and later
    except ImportError:
    from . import _compression

    It goes to the second import (which is likely broken, as it was not used since Python 3.5?).

  2. hroncok commented on May 29, 2025

    @hroncok
    import compression._common._streams as _compression

    should do on Python 3.14+

  3. hroncok commented on May 29, 2025

    @hroncok

    Considering

    python_requires=">=3.9",

    The from . import _compression fallback is likely not needed.

  4. added a commit that references this issue on Sep 24, 2025
  5. cclauss commented on Sep 24, 2025

    @cclauss
    Contributor

    % uvx --with=lz4 python3.14t -c"import lz4"

    <frozen importlib._bootstrap>:491: RuntimeWarning: The global interpreter lock (GIL) has been enabled
        to load module 'lz4._version', which has not declared that it can run safely without the GIL.
        To override this behavior and keep the GIL disabled (at your own risk), run with PYTHON_GIL=0
        or -Xgil=0.
    

    Reviews please on the solution proposed in:

  6. cclauss commented on Oct 7, 2025

    @cclauss
    Contributor
  7. cclauss commented on Oct 12, 2025

    @cclauss
    Contributor

    @corona10 This is green ✅ at the bottom of https://ft-checker.com/?search=lz4 but is not really usable on Py4.13.

  8. added a commit that references this issue on Oct 20, 2025
  9. added a commit that references this issue on Oct 20, 2025
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions