是否有一种方法可以将包作为脚本执行?例如:执行已安装的Python程序包作为脚本?
[~]# easy_install /path/to/foo.egg
...
[~]# python -m foo --name World
Hello World
我试图创建一个__main__.py
文件我的包内,但它没有被执行(我使用Python 2.6)。以下引发错误:
foo is a package and cannot be directly executed
我的包的结构如下:
foo/
setup.py
foo/
__init__.py
__main__.py
运行python -m foo.__main__ --name World
按预期工作,但我宁愿执行的前路。这可能吗?
https://stackoverflow.com/questions/6630822/running-a-python-package – n611x007 2015-05-21 09:34:03
有用的链接:https://www.reddit.com/r/Python/comments/2gki9e/python_apps_the_right_way_entry_points_and_scripts/ – 2016-02-05 04:08:27