为什么“eggsecutable”要搜索\uu main__

2024-09-26 22:53:31 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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

所以python找不到入口点。在

没有显式的__main__.py就可以生成一个可执行的egg吗?

系统:

  • 胜利7
  • Python 2.7.9
  • 来自c:\python27\lib\site packages(python27\lib\site packages(python2.7))的setuptools 39.0.1

更新

我在Linux上都用python3尝试过这两种方法,但我得到了相同的错误。在


Tags: 文件方法pyeggmainlibpackagessetup
1条回答
网友
1楼 · 发布于 2024-09-26 22:53:31

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

你可能想要这样的东西:

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

^{pr2}$

制作鸡蛋: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

相关问题 更多 >

    热门问题