Search code examples
python-3.xsetuptoolspackagingpython-packaging

how to pack python packages and sub-packages as single package in python3


I'm trying to create a python package with below structure. when i'm trying to create the package testproject it is creating successfully and uploading successfully to https://test.pypi.org/legacy/

testproject/
    testproject/
        Core/
            __init__.py
            BaseModel.py
        lib/
            __init__.py
            RunModel.py
        __init__.py
        RunWorkflow.py
    LICENSE
    README.md
    setup.py   

When i attempt to download it to my new environment it is downloading the correct version to my environment and when i run conda list i can see the installed package with correct version.

The actual problem is when i tried to run help('modules') command, it returns all the sub-packages [Core and lib] too. when i see other packages such as os, numpy, scikit-learn. it is not showing its sub-packages in help('modules').

how can i avoid this situation, am i doing anything wrong here ?

Please find my setup.py below.

import setuptools

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

setuptools.setup(
    name='Test-Project-pypi',
    version='0.0.1',
    author="Manikandan Jeyabal",
    author_email="[email protected]",
    description="My longdestription",
    long_description=long_description,
    long_description_content_type="text/markdown",
    packages=setuptools.find_packages(),
    classifiers=[
        "Development Status :: 3 - Alpha",
        "Intended Audience :: Developers",
        "Programming Language :: Python :: 3",
        "Programming Language :: Python :: 3.4",
        "Programming Language :: Python :: 3.5",
        "Programming Language :: Python :: 3.6",
        "License :: OSI Approved :: MIT License",
        "Operating System :: OS Independent",
    ],
    install_requires=[
        "numpy <=1.17.4", "pandas", "scikit-learn >= 0.21.3, <= 0.22"
    ],
    python_requires='>=3.7'
 )


Solution

  • This issue got resolved by adding the below code in Main init.py under 'testproject'

    from . import Core
    from . import lib