为什么 "eggsecutable" 搜索 __main__

Why does "eggsecutable" search for __main__

我尝试制作一个可执行的 *.egg 文件。我可以使用以下方法创建它:我只是将 __main__.py 放在名为 .zip.egg 的顶层,而 python 将 运行 __main__.py

我读到有一个更优雅的方法:

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

但是如果我创建(使用 运行 setup.py bdist_egg)和 运行 *.egg,它会打印: C:\Python27\python.exe: can't find '__main__' module in <eggpath>

所以python没有找到入口点。

是否可以在没有显式的情况下制作可执行的 egg __main__.py

系统:

更新

我在 Linux 上都用 python3 试过了,但我得到了同样的错误。

似乎入口点文档具有误导性,您不需要它们。

你可能想要这样的东西:

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()

创建鸡蛋:setup.py bdist_egg

运行鸡蛋:python dist\example_pkg-0.0.1-py3.6.egg

输出:egg test

解决方案来源:https://mail.python.org/pipermail/distutils-sig/2015-June/026524.html