3

I have a python package I published on PyPI, my file structure is this:

- setup.py
- example.py
- ...
- igloo
  - __init__.py
  - ...
  - models
    - __init__.py
    - user.py
    - ...

inside the file igloo/__init__.py I have this import statement

from igloo.models.user import User

When I import the package igloo from the example.py file (the import resolves to the folder igloo) everything works as expected, but when I install the package from pip and import it I get the error ModuleNotFoundError: No module named 'igloo.models' on the import line from the file igloo/__init__.py. In both cases I import the package like this:

from igloo import Client

The setup.py file is like this

from distutils.core import setup
setup(
    name='igloo-python',         # How you named your package folder (MyLib)
    packages=['igloo'],   # Chose the same as "name"
    version='0.9.3',
    license='MIT',
    description='Python client for igloo',
    author='Igloo Team',
    author_email='hello@igloo.ooo',
    url='https://github.com/IglooCloud/igloo_python',  
    download_url='https://github.com/IglooCloud/igloo_python/archive/v_09.tar.gz',
    keywords=['iot', 'igloo'],
    install_requires=[
        'requests', 'asyncio', 'pathlib', 'websockets', 'aiodataloader'
    ],
    classifiers=[
        'Development Status :: 5 - Production/Stable',
        'Intended Audience :: Developers',
        'Topic :: Software Development ',
        'License :: OSI Approved :: MIT License  ',
        'Programming Language :: Python :: 3',
    ],
)

I also tried replacing the import in igloo/__init__.py with

from .models.user import User

the same error pops up also in this case.

phd
  • 82,685
  • 13
  • 120
  • 165
Andrea
  • 133
  • 4
  • do you have an absolute import in your models.py file? Try running python with the `-v` flag to check import order. – thebjorn Apr 28 '19 at 13:16
  • 2
    Possible duplicate of [Why do I need to include sub-packages in setup.py](https://stackoverflow.com/questions/50083553/why-do-i-need-to-include-sub-packages-in-setup-py) – phd Apr 28 '19 at 15:34
  • https://stackoverflow.com/search?q=%5Bsetup.py%5D+list+all+subpackages – phd Apr 28 '19 at 15:34
  • `packages=['igloo', 'igloo.models'],` – phd Apr 28 '19 at 15:35

0 Answers0