I have a package I've been developing that I'm having trouble properly organizing in order for my scripts to work both after PyPI/pip install and also locally running it.
I primarily have two files, e.g. my-package.py
and utils.py
I'm looking to be import-able, one of which references the other. My desired file organization would be:
LICENSE
pyproject.toml
README.md
my-package/
__init__.py
my-package.py
utils.py
tests/
I would like to be able to pip install my-package
and then import this package in a new script like so:
from my-package import my-function
(or if I have to, from my-package.my-package import my-function
) and also from my-package.utils import util-function
But I also import a util-function from utils.py within my-package.py, and so far I've only been able to get it working for pip OR local, but not both.
E.g., This works after pip installing from my-package.my-package import my-function
and also from my-package.utils import util-function
. But when I locally try to run python my-package.py
, I get the error: ModuleNotFoundError: No module named 'my-package.utils'; 'my-package' is not a package
.
I've tried some variations with from .my-package
or from .utils
but these also have relative import errors.
I might be asking for too much here, but hoping theres some relatively painless guidance I could follow re: organization + importing that would make this work for both post-pip importing and for locally running the scripts?
Thanks for all the help!