Reputation: 2511
I am trying to test changes to a Python module, let's call it my_import_module
. Currently, it's in a site package. I would like to import it from my local file structure, not from my site packages.
The folder structure looks like this:
dir
|--dirA
|--dirB
|--my_import_file.py
|--__init__.py
|--dirC
|--dirD
|--main.py
|--__init__.py
I am trying to import the file my_import_file.py
into main.py
, and not from the site packages version.
Currently I have from ../../dirA.dirB.my_import_file import XYZ
. This doesn't work.
I would like to not add __init__.py
into each directory.
Two questions:
my_import_file.py
from the directory instead of from site packages?my_import_file
?Upvotes: 0
Views: 2043
Reputation: 7241
See https://www.python.org/dev/peps/pep-0328/
The way to do is
from ...dirA.dirB.my_import_file import XYZ
Upvotes: 1