I recently developed a package with the following structure:
.
├── Foo
│ ├── module1.py
│ ├── module2.py
│ ├── __init__.py
where we have:
#__init__.py
from module1 import function1, function2
from module2 import function3
#module1.py
def function1():
print("Hello")
def function2():
print("World")
#module2.py
def function3():
print("Hello again")
I wish to be able to import my full package Foo at once from another directory (with no relative path I can relate to).
For instance, I would like to be able to call Foo.module1.function1()
in my scripts on another drive.
I cannot use sys.path, and I cannot just move either my script or package into parent/child directories.
I know I can import all modules one by one from a specific directory using importlib (cf. How to import a module given the full path?), and then looping, for instance with glob, but I read that configuring the __init__
file should allow me to import everything at once. Any advice ? (for what it matters, using Python3.9, with no access to PyCharm)