package - Python Egg failing to load sub-modules in my project -
i trying create egg package python project build using cement (builtoncement) library
my project structure looks this
connector readme.md requirements.txt setup.py __main.py__ __init.py__ lib __init__.py handlers __init__.py logging __init__.py logstashhandler.py
the contents of __main.py__
is
import sys import os cement.core.foundation import cementapp lib.handlers.logging.logstashhandler import logstashhandler …… class connectorapp(cementapp): def main(): log = none connectorapp() app: log = app.log if __name__ == '__main__': main()
the contents of setup.py is
#!/usr/bin/env python import uuid setuptools import setup import os pip.req import parse_requirements def read(fname): return open(os.path.join(os.path.dirname(__file__), fname)).read() base_dir = os.path.dirname(os.path.realpath(__file__)) reqs_file = os.path.join(base_dir, 'requirements.txt') install_reqs = parse_requirements(reqs_file, session=uuid.uuid1()) setup( name="connectors", version="0.1", author="pradeep mishra", install_requires=["argparse", "requests", "pyyaml", "datetime", "cement"], packages=['lib'], long_description=read('readme.md'), data_files=[ ('', ['__main__.py', ])], classifiers=[ "programming language :: python :: 2.7" ], )
i installing program using below commands
python setup.py build python setup.py sdist python setup.py bdist_egg
when try run program going dist folder, getting following error:
(venv) pradeeps-macbook-pro:dist pradeepmishra$ python connectors-0.1-py2.7.egg traceback (most recent call last): file "/system/library/frameworks/python.framework/versions/2.7/lib/python2.7/runpy.py", line 162, in _run_module_as_main "__main__", fname, loader, pkg_name) file "/system/library/frameworks/python.framework/versions/2.7/lib/python2.7/runpy.py", line 72, in _run_code exec code in run_globals file "connectors-0.1-py2.7.egg/__main__.py", line 4, in <module> importerror: no module named handlers.logging.logstashhandler
please help. how can tell egg builder locate modules , sub-modules inside lib module
i found myself. instead of specifying top level package in packages, passed function find_packages() , worked charm.
my setup function looks #!/usr/bin/env python
import uuid setuptools import setup, find_packages import os pip.req import parse_requirements def read(fname): return open(os.path.join(os.path.dirname(__file__), fname)).read() base_dir = os.path.dirname(os.path.realpath(__file__)) reqs_file = os.path.join(base_dir, 'requirements.txt') install_reqs = parse_requirements(reqs_file, session=uuid.uuid1()) setup( name="connectors", version="0.1", author="pradeep mishra", install_requires=["argparse", "requests", "pyyaml", "datetime", "cement"], packages=find_packages(), long_description=read('readme.md'), data_files=[ ('', ['__main__.py', ])], classifiers=[ "programming language :: python :: 2.7" ],
)
Comments
Post a Comment