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

ModuleNotFoundError: No module named 'zoneinfo' #122

Closed
amotl opened this issue Oct 18, 2022 · 3 comments
Closed

ModuleNotFoundError: No module named 'zoneinfo' #122

amotl opened this issue Oct 18, 2022 · 3 comments

Comments

@amotl
Copy link

amotl commented Oct 18, 2022

Dear Paul,

thanks a stack for maintaining this package. I just used it for the very first time, and copied the snippet from the README as advertised, and how I expected it to work out of the box. Using a try/except on an ImportError is usually what we are all used to do since ages, right?

Now I was baffled to find that in this case, Python 3.8 reports a ModuleNotFoundError. I think it probably always have been like that, ImportError would only be raised in from abc import foo-style cases, where the top-level package module exists, but not a submodule.

I just wanted to make sure you agree on this before I would submit a corresponding patch to the README.

try:
    import zoneinfo
except ModuleNotFoundError:
    from backports import zoneinfo

With kind regards,
Andreas.

Reproduction

docker run --rm -it python:3.8-slim-bullseye
>>> import zoneinfo
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'zoneinfo'
@pganssle
Copy link
Owner

Hi Andreas,

ModuleNotFoundError is a subclass of ImportError. You can catch either ImportError or ModuleNotFoundError, and I tend to just always catch ImportError. I'm not sure that the README needs to be updated.

@amotl
Copy link
Author

amotl commented Oct 24, 2022

Hi Paul,

oh you are right. I don't know why this issue happened to me. I will close it and may come back to it when I will be able to re-evaluate the problems I've observed, if any.

With kind regards,
Andreas.

@amotl
Copy link
Author

amotl commented Oct 24, 2022

As expected, everything works flawlessly when using ImportError again with crate/crate-python@4d655b6c2, tested on behalf of crate/crate-python#466. I don't know what went wrong before, so again sorry for the noise.

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

2 participants