Date Tags Python

如果想要在python中使用好像java一样的namespace, 又想发布到不一样的egg下面,就必须按以下修改

Package-1/example/__init__.py
Package-1/example/module1/__init__.py
Package-1/setup.py
Package-2/example/__init__.py
Package-2/example/module2/__init__.py
Package-2/setup.py

Package-1/setup.py内容

from setuptools import setup, find_packages
import sys
setup(name='example-a',
      version='1.0',
      include_package_data=True,
      )

Package-2/setup.py内容

from setuptools import setup, find_packages
import sys
setup(name='example-b',
      version='1.0',
      include_package_data=True,
      )

Package-1/example/init.py和Package-2/example/init.py内容

import pkg_resources
pkg_resources.declare_namespace(__name__)

参考:

  • http://stackoverflow.com/questions/1675734/how-do-i-create-a-namespace-package-in-python
  • http://www.python.org/dev/peps/pep-0382/