I am creating my own python library: toolbox
. In the end I want to be able to do: from toolbox.printing import warn
.
My architecture looks like this:
repo
|--toolbox
|----__init__.py
|----printing
|------__init__.py
|------utils.py
|--demo.py
|--setup.py
Here is toolbox/printing/utils.py
:
def warn(text: str):
print(str)
I was able to run demo.py
with this:
from toolbox.printing import warn
warn("This is a warning")
with toolbox/__init__.py
:
from .printing import warn
and toolbox/printing/__init__.py
from .utils import warn
This works fine when executing python demo.py
.
However if in another project I do pip install git+myRepo.git
, the import does not work. The error depended on what I put in the __init__.py
files: ModuleNotFOundError, CircularImports, ...
Here is my setup.py
file:
import setuptools
with open("README.md", "r", encoding="utf-8") as fh:
long_description = fh.read()
setuptools.setup(
name='toolbox',
version='0.0.1',
author='MyName',
author_email='myEmail',
description='Usefull functions for my personnal use',
long_description=long_description,
long_description_content_type="text/markdown",
url='myRepo',
project_urls = {
"Bug Tracker": "myRepo"
},
license='MIT',
packages=['toolbox'],
install_requires=['requests',
'boto3',
'configparser'],
)
Could someone explain me:
- What I should put in the
__init__.py
files so that it works? - What exactly is happening here? Is this a difference between modules and libraries?
Thanks!
See above for mor details.