Search code examples
pythonexecutablesetuptoolsegg

Why does "eggsecutable" search for __main__


I try to make a executable *.egg file. I can create this using the following method: I just put a __main__.py at the top-level of an .egg named .zip, and python will run that __main__.py

I have read that there is a more elegant way:

setup(
    # other arguments here...
    entry_points={
        'setuptools.installation': [
            'eggsecutable = my_package.some_module:main_func',
        ]
    }
)

https://setuptools.readthedocs.io/en/latest/setuptools.html#eggsecutable-scripts

But if I create ( with run setup.py bdist_egg) and run the *.egg, it prints: C:\Python27\python.exe: can't find '__main__' module in <eggpath>

So python doesn't find the entry point.

Is it possible make an executable egg without explicit __main__.py?

System:

  • Win 7
  • Python 2.7.9
  • setuptools 39.0.1 from c:\python27\lib\site-packages (Python 2.7))

UPDATE

I have tried both on Linux both with python3 and I got the same error.


Solution

  • It seems like the entry points documentation is misleading and you don't need them.

    What you probably want something like this:

    setup.py:

    import setuptools
    
    setuptools.setup(
        name="example_pkg",
        version="0.0.1",
        # all the other parameters
    
        # function to call on $ python my.egg
        py_modules=['example_pkg.stuff:main']
    )
    

    example_pkg/stuff.py

    def main():
        print("egg test")
    
    if __name__ == '__main__':
        main()
    

    create the egg: setup.py bdist_egg

    run the egg: python dist\example_pkg-0.0.1-py3.6.egg

    output: egg test

    solution source: https://mail.python.org/pipermail/distutils-sig/2015-June/026524.html