Amusing ImportError due to implicit relative import

rosuav@sikorsky:~$ python3 -m asyncio
asyncio REPL 3.12.0a6+ (heads/main:72186aa637, Mar 18 2023, 09:14:09) [GCC 10.2.1 20210110] on linux
Use "await" directly instead of "asyncio.run()".
Type "help", "copyright", "credits" or "license" for more information.
>>> import asyncio
>>> 
exiting asyncio REPL...

rosuav@sikorsky:~/cpython/Lib/asyncio$ python3 -m asyncio
Traceback (most recent call last):
  File "<frozen runpy>", line 189, in _run_module_as_main
  File "<frozen runpy>", line 148, in _get_module_details
  File "<frozen runpy>", line 112, in _get_module_details
  File "/usr/local/lib/python3.12/asyncio/__init__.py", line 8, in <module>
    from .base_events import *
  File "/usr/local/lib/python3.12/asyncio/base_events.py", line 25, in <module>
    import subprocess
  File "/home/rosuav/cpython/Lib/asyncio/subprocess.py", line 5, in <module>
    from . import events
ImportError: attempted relative import with no known parent package

It’s the classic “oh you have a file in your working directory with the same name as a stdlib module”, except that my working directory IS the stdlib.

This isn’t really a help request, more just a “heh, it can happen accidentally even without any obvious mistake”, but I don’t think there’s a good category on Discourse for random-point-of-amusement :slight_smile:

1 Like