Author Rosuav
Recipients Arfrever, Rosuav, brett.cannon, eric.snow, flox, ncoghlan, pitrou
Date 2016-01-14.21:55:11
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
This still happens in current CPython, and doesn't even require a package:

rosuav@sikorsky:~$ echo 'from . import x' >
rosuav@sikorsky:~$ python3
Traceback (most recent call last):
  File "", line 1, in <module>
    from . import x
SystemError: Parent module '' not loaded, cannot perform relative import

This just caused some confusion for a student of mine who had migrated from Python 2. Converting intra-package imports from "import spam" to "from . import spam" made them work; converting a non-package import the same way caused this problem. ImportError would be massively preferable.

But I'm not understanding something here. If I set __package__ inside the module, the behaviour changes accordingly:

rosuav@sikorsky:~$ cat 
__package__ = 'sys'
from . import version
rosuav@sikorsky:~$ python3 
3.6.0a0 (default:ac94418299bd+, Jan 15 2016, 08:44:02) 
[GCC 4.9.2]

Leaving __package__ unset has it implicitly be None. Whether it's None or '', the package checks should simply not be made - see three lines above the line Brett linked to (in today's code, that's - hasn't changed). So I'm not sure why the checks are even happening. However, that probably means more about my exploration and testing than it does about the code; editing the text of the message doesn't result in a change, so I'm obviously not updating the frozen version.
Date User Action Args
2016-01-14 21:55:11Rosuavsetrecipients: + Rosuav, brett.cannon, ncoghlan, pitrou, Arfrever, flox, eric.snow
2016-01-14 21:55:11Rosuavsetmessageid: <>
2016-01-14 21:55:11Rosuavlinkissue18018 messages
2016-01-14 21:55:11Rosuavcreate