0

I have the following directory structure:

top/
    mod1.py
    pkg1/
        mod2.py

The goal is to import objects from mod1.py inside the mod2.py file, Eventually I might have to use more complicated figures, like if there had been another directory with other modules on the mod1.py file level, but in neither of the 2 cases am I being able to import the required objects (inside mod2.py):

from ..mod1 import *

,

from .mod1 import *

I'm using Python 3.8.0, Any thoughts? Thanks.

Saurav Saha
  • 745
  • 1
  • 11
  • 30
Tom
  • 55
  • 7
  • Does this answer your question? [Importing files from different folder](https://stackoverflow.com/questions/4383571/importing-files-from-different-folder) – effy Feb 21 '20 at 18:13
  • What do you mean by "not able to import the required objects"? Do you get an error? Do the objects fail to show up? – MisterMiyagi Feb 21 '20 at 20:31
  • Depends, gives me: ```no module name```, or ```attempted to relative import with not known parent package```. – Tom Feb 21 '20 at 20:42
  • @effy Thanks, so far ```sys.path.append('../')``` solved the problem; it's still not perfect, the best would be, imo, to not messing with ```PATH```; but it allows me to keep going though. – Tom Feb 21 '20 at 20:44

0 Answers0