:\codepython import pkg spam eggseggseggseggs ok as package but not program in both and :\codepython pkg\main py systemerrorcannot perform relative import :\codepython pkg\spam py systemerrorcannot perform relative import fix package subdirectories in mixed-use case like thisone solution is to isolate all but the main files used only by the program in subdirectory--this wayyour intrapackage imports still work in all pythonsyou can use the top directory as standalone programand the nested directory still serves as package for use from other programscode\pkg\main py import sub spam <=works if move modules to pkg below main file code\pkg\sub\spam py from import eggs package relative works nowin subdirectory code\pkg\sub\eggs py print('eggs :\codepython pkg\main py eggseggseggseggs from main scriptsame result in and :\codepython import pkg sub spam eggseggseggseggs from elsewheresame result in and the potential downside of this scheme is that you won' be able to run package modules directly to test them with embedded self-test codethough tests can be coded separately in their parent directory insteadc:\codepy - pkg\sub\spam py but individual modules can' be run to test systemerrorcannot perform relative import fix full path absolute import alternativelyfull path package import syntax would address this case too--it requires the directory above the package root to be in your paththough this is probably not an extra requirement for realistic software package most python packages will either require this settingor arrange for it to be handled automatically with install tools (such as distutilswhich may store package' code in directory on the default module search path such as the site-packages rootsee for more details)code\pkg\main py import spam package relative imports