Author ncoghlan
Recipients ADataGman, brett.cannon, docs@python, eric.snow, ncoghlan, terry.reedy
Date 2019-02-12.13:17:57
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
As discussed in and the cryptic error message here is due to the relative import being resolved based on the module name "__main__", since the submodule was executed directly, rather than the intended "sound.filter.vocoder" name that it would have when imported or executed via the "-m" switch.

It's spectacularly unobvious what's going on if you're not deeply familiar with the intricacies of main module execution, but I haven't had any great ideas for practical ways to improve the error message.

I'm not sure we currently have access to the required info at the point this error is raised, but perhaps it would be enough to add the name of the module doing the import to the error message as a reminder that directly executing scripts inside packages does weird things to import resolution?

Something like:

  "Attempted relative import beyond top-level package '__main__'"
Date User Action Args
2019-02-12 13:17:57ncoghlansetrecipients: + ncoghlan, brett.cannon, terry.reedy, docs@python, eric.snow, ADataGman
2019-02-12 13:17:57ncoghlansetmessageid: <>
2019-02-12 13:17:57ncoghlanlinkissue35927 messages
2019-02-12 13:17:57ncoghlancreate