Nick Coghlan <ncogh...@gmail.com> added the comment:

As discussed in 
http://python-notes.curiousefficiency.org/en/latest/python_concepts/import_traps.html#executing-the-main-module-twice
 and https://www.python.org/dev/peps/pep-0395/#why-are-my-imports-broken 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__'"

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue35927>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to