Skip to content

ImportError when attempting to test with Python 3.14 #302

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

Open
befeleme opened this issue May 29, 2025 · 3 comments · May be fixed by #303
Open

ImportError when attempting to test with Python 3.14 #302

befeleme opened this issue May 29, 2025 · 3 comments · May be fixed by #303

Comments

@befeleme
Copy link

befeleme commented May 29, 2025

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)
@hroncok
Copy link

hroncok commented May 29, 2025

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?).

@hroncok
Copy link

hroncok commented May 29, 2025

import compression._common._streams as _compression

should do on Python 3.14+

@hroncok
Copy link

hroncok commented May 29, 2025

Considering

python_requires=">=3.9",

The from . import _compression fallback is likely not needed.

@befeleme befeleme linked a pull request May 29, 2025 that will close this issue
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.

2 participants