2

I have created a package with the following structure in the dev branch (not merging to main until I verify the package installs correctly):

mypackage
|
|-- __init__.py
|-- setup.py
|-- requirements.txt
|-- module.py
|-- subpackage_one
    |
    |-- __init__.py
    |-- module_ab.py
        |-- class_aba
        |-- class_abb
    |-- module_ac.py
        |-- function_aca

|-- subpackage_two
    |
    |-- __init__.py
    |-- module_ba.py
        |-- function_baa

Additional information:

  • The __init__.py files at root and in subpackage__two are both empty
  • The __init__.py file in subpackage_one contains some additional initialization in the form of from mypackage.subpackage_one.module_xx import class_xxx (or function_xxx)
  • I am installing the package via pip install git+https://github.com/organization/repo.git@dev
  • If I am in the root directory of the package, I can import the submodules as expected
  • The setup.py file is:
import setuptools

with open("README.md", "r", encoding="utf-8") as fh:
    long_description = fh.read()

setuptools.setup(
    name='mypackage',
    version='0.0.2',
    author='author1, author2',
    author_email='author1_email, author2_email',
    description='My Package',
    long_description=long_description,
    long_description_content_type="text/markdown",
    url='https://github.com/organization/repo',
    packages=['mypackage'],
    install_requires=['requests'],
)
  • When I run the following snippet:
import pkgutil
for i in pkgutil.iter_modules(mypackage.__path__):
    print(i)

I see:

ModuleInfo(module_finder=FileFinder('/path/to/package/mypackage'), name='module', ispkg=False)

And indeed, the subpackages are not in the mypackage folder.

How can I get the subpackages to install along with the package?

1 Answer 1

1

Your issue might be the packages parameter. It needs to be supplied with every module or 'package'.

setuptools has a nice function to find them, use it like this: packages=setuptools.find_namespace_packages(),

Sign up to request clarification or add additional context in comments.

2 Comments

Ok that mostly worked. It downloads the subpackage folder and associated modules. I failed to mention (didn't think it was relevant) that I have some json files inside subpackage_two that aren't showing up now. Any suggestions there? Thanks
Never mind I found the answer here regarding the missing data stackoverflow.com/questions/30164073/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.