I am trying to create a package in Python that has a number of sub-packages (I'm not sure if that's the right term for them) which need to interoperate.
I have a (simplified) structure like this:
/package
|-script1.py
|-script2.py
|-subpackage1
| |-__init__.py
| |-src
| | |-__init__.py
| | |-my_program.py
| | |-functions.py
| | |-...
|
|-tests
| |-a_tests.py
|-subpackage2
| |-web-server.py
| |-API
| | |-__init__.py
| | |-REST.py
| | |-...
package/subpackage2
needs to be able to callpackage/subpackage1/src/functions.py
package/tests
calls both subpackages (usingpytests
).package/subpackage1/src/functions.py
needs to be able to call other modules withinsubpackage1
I've seen this answer: https://stackoverflow.com/a/33195094 - which explains what I need to do (create a package), but it doesn't explain how to do it.
I can readily get the two scripts
to call their component sub-packages using:
import subpackage1.src.my_program.py
(i.e. similar to the suggestions here) but then my_program.py
fails with an ImportError: No module named 'functions'
So, what glue do I need to set this structure up?