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

ImportError: cannot import name 'tarfile' from 'backports' #5

Closed
efranzmann opened this issue Apr 9, 2024 · 6 comments
Closed

ImportError: cannot import name 'tarfile' from 'backports' #5

efranzmann opened this issue Apr 9, 2024 · 6 comments
Assignees

Comments

@efranzmann
Copy link

efranzmann commented Apr 9, 2024

Describe the bug
I'm using astroquery with the jplhorizons module which uses keyring as a dependency. I had a student do a fresh install, and she's getting an error that traces back to keyring:

ImportError: cannot import name 'tarfile' from 'backports' (/opt/conda/lib/python3.11/site-packages/backports/__init__.py)

As an experiment I upgraded to the most recent version of keyring and am now seeing the error. Downgrading to keyring 24.3 (which is the version I had previously) fixes the issue.

backports.tarfile downloaded when I installed 25.1, if I'm interpreting things correctly the issue is that it doesn't seem to be finding it.

To Reproduce
Steps to reproduce the behavior:

  1. pip install -U --user --pre astroquery
  2. pip install -U --user keyring
  3. in python: from astroquery.jplhorizons import Horizons

Expected behavior
Module imports and works (as with keyring 24.3)

Environment
Linux of some kind; this is on a JupyterHub run by a 3rd party. Python 3.11.6

$ pip list | grep keyring
keyring                       25.1.0
...
$ keyring --list-backends
Traceback (most recent call last):
  File "/home/jupyter/.local/bin/./keyring", line 5, in <module>
    from keyring.cli import main
  File "/home/jupyter/.local/lib/python3.11/site-packages/keyring/__init__.py", line 1, in <module>
    from .core import (
  File "/home/jupyter/.local/lib/python3.11/site-packages/keyring/core.py", line 11, in <module>
    from . import backend, credentials
  File "/home/jupyter/.local/lib/python3.11/site-packages/keyring/backend.py", line 14, in <module>
    from jaraco.context import ExceptionTrap
  File "/home/jupyter/.local/lib/python3.11/site-packages/jaraco/context.py", line 17, in <module>
    from backports import tarfile
ImportError: cannot import name 'tarfile' from 'backports' (/opt/conda/lib/python3.11/site-packages/backports/__init__.py)

Additional context
Add any other context about the problem here.
backports

@jaraco jaraco self-assigned this Apr 16, 2024
@jaraco
Copy link
Owner

jaraco commented Apr 16, 2024

I took a quick look at running the tests on Python 3.11 and they pass on my machine. There may be something more insidious going on on your side. Aha! I think I see the problem in site-packages/backports/__init__.py. The presence of that file indicates that there's another backports module masking the presence of backports.tarfile. Oh, right, because something is installed system-wide that's using the pkgutil-style namespace package, but backports.tarfile is installed in the user path and uses PEP 420 native namespace packages. Root of the issue is at brandon-rhodes/backports#1. I need to revisit that.

Can you identify what other backports you have installed by ls /opt/conda/lib/python3.11/site-packages/backports? Thanks.

@efranzmann
Copy link
Author

Thanks for your reply! Result of the command:

$ ls /opt/conda/lib/python3.11/site-packages/backports 
functools_lru_cache.py  __init__.py  __pycache__

@jaraco
Copy link
Owner

jaraco commented Apr 22, 2024

I've confirmed that functools_lru_cache does in fact still use pkgutil style packages, so probably backports.tarfile should do the same. I'll transfer the issue there.

@jaraco jaraco transferred this issue from jaraco/keyring Apr 22, 2024
@jaraco jaraco closed this as completed in 76e9454 Apr 22, 2024
@alesimattia
Copy link

I've confirmed that functools_lru_cache does in fact still use pkgutil style packages, so probably backports.tarfile should do the same. I'll transfer the issue there.

Hi, I second the question since I have the same issue and have not resolved.
Could you tell how to "do the same" please?

@jaraco
Copy link
Owner

jaraco commented Jul 18, 2024

See the linked commit 76e9454.

Note that Setuptools 71 recently introduced a bug (pypa/setuptools#4476) that produced this error message, but was unrelated to how any backports.* package was organized.

@alesimattia
Copy link

Thank you

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

No branches or pull requests

3 participants