This is my first time making a python package, and I am thoroughly confused about __init__.py
, __main__.py
, and their relation to making a package.
Here is my project structure:
package_name/
setup.py
README.md
LICENSE
package_name/
__init__.py
__main__.py
A.py
B.py
Class A in A.py
depends on a class B in B.py
.
Should I have both __init__.py
and __main__.py
?
What should be in the files?
What I have tried:
in A.py
:
from B import B
and from .B import B
The first allows me to run normally locally, but when I try to upload it to pypi and install it, I get ModuleNotFoundError: No module named 'B'
The second allows me to import it after installing it from pypi, but I can't run it normal locally.
My goal is to import Class A from the package with the following
from package_name import A
and be able to run my package locally.
Edit: I am using Python 3.