Python 3.4 setuptools namespace setup does not wor

2019-07-15 03:32发布

问题:

I am trying to create namespace packages for a modular project. The core system has the following packages

homie
homie.api
homie.events
homie.mods

I want to install the respective modules as sub-packages of homie.mods.

Therefor I provided the respective homie.__init__.py and homie.mods.__init__.py with the following content:

from pkg_resources import declare_namespace

declare_namespace(__name__)

My testing module is structured as follows:

homie
homie/__init__.py
homie/mods
homie/mods/__init__.py
homie/mods/test
homie/mods/test/__init__.py

Where homie/__init__.py and homie/mods/__init__.py contain:

from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)

and homie/mods/test/__init__.py contains

print('Works!')

The core package is being set up with the following setup.py:

from setuptools import setup

<snip>

setup(
    name='homie',
    version=version,
    author=author,
    author_email=author_email,
    install_requires=[
        'docopt',
        'setproctitle',
        'homeinfo',
        'homeinfo-crm',
        'openimmo',
        'zmq'
    ],
    packages=[
        'homie',
        'homie.api',
        'homie.events',
        'homie.mods'
    ],
    namespace_packages=['homie', 'homie.mods'],
<snip>

which I install first. Sencondly I install the module using its setup.py:

#! /usr/bin/env python3

from setuptools import setup

setup(name='homie-test',
      version=version,
      author=author,
      author_email=email,
      install_requires=['homie'],
      packages=['homie.mods.test'],
      namespace_packages=['homie', 'homie.mods'],
      license=open('LICENSE.txt').read()
      )

When trying to import stuff, I get the following:

>>> from homie import api, events, mods
>>> from homie.mods import test
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'test'
>>> 

What am I missing?