0

I have created a python library whose structure looks like this.

|/library_name
|    |__init__.py
|    |/subpackage
|    |   |__init__.py
|    |   |
|setup.py
|setup.cfg
|LICENSE

Now when i published in pypi, I couldn't see the inner subpackages installed along with it. What should I do? What should be in outer __init__.py. Assume inner __init__.py has classes which I have written. Somebody please help how to add subpackages to the python library.

Here's the setup.py format

setup(
  name = 'package',         
  packages = ['package'],
  version = '1.0.1',
  license='GNU General Public Version 3',
  description = 'Package is the open source Python Library for solving various AI needs',
  long_description = long_description,
  long_description_content_type = "text/markdown",
  author = ['Vigneshwar K R'],
  author_email = '[email protected]',
  url = 'https://github.com/ToastCoder/repo',
  download_url = 'https://github.com/ToastCoder/repo/archive/master.zip',
  keywords = ['ARTIFICIAL INTELLIGENCE', 'TENSORFLOW'],
  install_requires=['tensorflow'],
  classifiers=[
    'Development Status :: 5 - Production/Stable',
    'Intended Audience :: Developers',
    'Intended Audience :: Science/Research',
    'Intended Audience :: Education',
    'Topic :: Software Development :: Build Tools',
    'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
    'Programming Language :: Python :: 3',      
    'Programming Language :: Python :: 3.4',
    'Programming Language :: Python :: 3.5',
    'Programming Language :: Python :: 3.6',
    'Programming Language :: Python :: 3.7',
    'Programming Language :: Python :: 3.8',
    'Programming Language :: Python :: 3.9'
  ],
)
3
  • 2
    What does your setup.py look like? Maybe you forgot to add find_packages? Commented May 27, 2021 at 13:12
  • Could you please mention what it does? Commented May 27, 2021 at 13:21
  • @AlexanderL.Hayes I have added contents in setup.py. Kindly check now. Commented May 27, 2021 at 13:26

1 Answer 1

2

Could you share said setup.py & __init__.py codes please ?

I see two ways to deal with this :

  • make the content from lib/submodule available from the top level : in lib/__init__.py add from submodule import *, then add every imported name in __all__. As far as i know, this is bad practice everywhere BUT inside of __init__.pys

  • add the submodule directory to setup.py's packages parameter : packages=["lib", "lib.submodule"]

edit: as i expected, submodule is missing from the packages parameter, so it is not considered needed.

the find_packages option commented about has the same effect as adding lib.submodule to the packages list, it is mainly used in large libraries where adding every single module manually would be a pain.

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

2 Comments

I have updated setup.py format in the same question. kindly check it out. Also which init.py you are asking? the outer or the inner init.py
lib.__init__.py is meant to be the outter one, the one at the top level. Also, i edited my answer

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.