import pkg eggs <=full package paths work in all cases + code\pkg\eggs py print('eggs :\codeset pythonpath= :\code :\codepython pkg\main py from main scriptsame result in and eggseggseggseggs :\codepython import pkg spam eggseggseggseggs from elsewheresame result in and unlike the subdirectory fixfull path absolute imports like these also allow you to run your modules standalone to testc:\codepython pkg\spam py eggseggseggseggs individual modules are runnable too in and exampleapplication to module self-test code (previewto summarizehere' another typical example of the issue and its full path resolution this uses common technique we'll expand on in the next but the idea is simple enough to include as preview here (though you may want to review this again later--the coverage makes more sense hereconsider the following two modules in package directorythe second of which includes self-test code in shorta module' __name__ attribute is the string "__main__when it is being run as top-level scriptbut not when it is being importedwhich allows it to be used as both module and scriptcode\dualpkg\ py def somefunc()print(' somefunc'code\dualpkg\ py import here replace me with real import statement def somefunc() somefunc(print(' somefunc'if __name__ ='__main__'somefunc(self-test or top-level script usage mode code the second of these needs to import the first where the import here placeholder appears replacing this line with relative import statement works when the file is used as packagebut is not allowed in nonpackage mode by either or (results and error messages are omitted here for spacesee the file dualpkg\results txt in the book' examples for the full listing)code\dualpkg\ py from import module packages