Attempted Relative Imports Beyond Top-level Package?
I have a directory structure like the following: game/ graphics/ __init__.py render.py sound/ __init__.py echo.py __init__.py and
Solution 1:
Do you need a relative import?
Can you use from game.sound.echo import echo_test
?
Though, since you haven't shown the exact stacktrace, the error could be coming from echo.py
. An attempted "import beyond top-level package" is self-explanatory, though.
PEP 328 could be worth a read
Solution 2:
I'm guessing that you are trying the following, or something similar: python render.py
But this is treating render.py as a script and not a component of a package. If you write an external script, where you
import render
, and then test render
functions, the imports should work fine.
You may want to have a look at Hitchhiker's Guide to Python
Post a Comment for "Attempted Relative Imports Beyond Top-level Package?"