I am trying to make a package in Python. I have the following file and directory structure:
.
├── ds
│ ├── __init__.py
│ ├── __main__.py
│ ├── package_a
│ │ ├── __init__.py
│ │ └── package_a_b
│ │ └── __init__.py
│ └── settings.py
├── install.sh
├── LICENSE
├── Manifest.in
├── README.md
└── setup.py
The code is the following:
ds/__init__.py
Empty file
ds/__main__.py
from package_a import name_a
from package_a.package_a_b import name_a_b
from settings import config
def main():
print(name_a)
print(config)
ds/package_a/__init__.py
name_a = 'name_a'
ds/package_a_b/__init__.py
name_a_b = 'name_a_b'
setup.py
import pathlib
from setuptools import setup
HERE = pathlib.Path(__file__).parent
README = (HERE / "README.md").read_text()
setup(
name="ds",
version="2.0.0",
long_description=README,
long_description_content_type="text/markdown",
license="MIT",
classifiers=[
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.8",
],
packages=["ds"],
#packages=find_packages(exclude=("tests",)),
include_package_data=True,
entry_points={
"console_scripts": [
"ds=ds.__main__:main",
]
},
)
In order to install I following these steps
rm -rf dist
pip uninstall ds
python setup.py bdist_wheel
pip install dist/ds-2.0.0-py3-none-any.whl --force-reinstall
ds
the problem is that when I execute ds I got the following message
ModuleNotFoundError: No module named 'settings'
if I comment all about settings then I get this error:
ModuleNotFoundError: No module named 'package_a'
So python is not finding the packages.
How can I solve this?
Your package inside
is available under the name __main__.py
ds
.
from ds.package_a import name_a
from ds.package_a.package_a_b import name_a_b
from ds.settings import config