I have some folders and
ImportError: No module named 'code.subcode'; 'code' is not a package
AttributeError: module 'code' has no attribute 'subcode'
The problem is that you are importing another module named
code that is installed on your system rather than your own module. You can verify this by checking the module file path in
code.__file__ after you
The first thing to do is change the name of your module to avoid namespace collisions with the other
code package on your system. If your new package name doesn't collide with something else, you should now either successfully be importing it and have it behave as expected, or it fails to import entirely.
If it fails to import, it is most likely because your
parent directory is not in your
PYTHONPATH environment variable.
There can potentially also be other more technical reasons that a module is not recognized by the interpreter such as old definitions being cached (in which case restarting the interpreter is often enough. Possibly after deleting any precompiled versions of the module). Another problem I have seen ended up being that a module contained a bug that made the interpreter unable to parse it. I am sure there are other odd possibilities out there.