【问题标题】:Why does "eggsecutable" search for __main__为什么“eggsecutable”搜索 __main__
【发布时间】:2018-10-08 06:51:05
【问题描述】:

我尝试制作一个可执行的*.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

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

所以python没有找到入口点。

是否可以在没有明确的__main__.py 的情况下制作可执行的鸡蛋?

系统:

  • 赢 7
  • Python 2.7.9
  • 来自 c:\python27\lib\site-packages (Python 2.7) 的 setuptools 39.0.1)

更新

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

【问题讨论】:

  • my_package.some_module 中有 main_func 吗?
  • 是的,它有。我已经检查过,通过将egg 添加到路径,我可以导入my_package.some_module 并调用main_func
  • 我在 Win 10、Python 3.6.5 和 setuptools 39.0.1 下遇到了同样的问题 我正在使用 [这里][1] 所示的示例项目,我无法自动放置__main__.py 在鸡蛋的顶层。我把__main__.py放在setup.py之外,但它最终被移到了包中,所以它在.egg内的位置是example_pkg/__main__.py [1]:packaging.python.org/tutorials/packaging-projects

标签: python executable setuptools egg


【解决方案1】:

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

你可能想要这样的东西:

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

【讨论】:

    猜你喜欢
    • 2011-05-01
    • 2013-04-11
    • 2016-09-23
    • 1970-01-01
    • 2018-11-22
    相关资源
    最近更新 更多