I am trying to be a good Pythonista and following PEP 338 for my package I plan on deploying.
我正在努力成为一名优秀的Pythonista,并追随PEP 338,为我的一揽子计划部署。
I am also trying to generate my executable scripts upon python setuptools install
using setuptools entry_points{'console_scripts': ... }
options.
我还在尝试使用setuptools entry_points{'console_scripts':…}选项。
How can I use entry_points to generate a binary that calls python -m mypackage
(and passes *args, **kwargs) ?
如何使用entry_points生成一个调用python -m mypackage(并传递*args、**kwargs)的二进制文件?
Here are a few attempts I have made with no success:
这里有几次我没有成功的尝试:
setuptools(
...
(1)
(1)
entry_points=
{'console_scripts': ['mypkg=mypkg.__main__'],},
(2)
(2)
entry_points=
{'console_scripts': ['mypkg=mypkg.main'],},
(3)
(3)
entry_points=
{'console_scripts': ['mypkg=python -m mypkg'],},
Primary resources I have been using:
我一直在使用的主要资源:
- http://pythonhosted.org/setuptools/setuptools.html#automatic-script-creation
- http://pythonhosted.org/setuptools/setuptools.html automatic-script-creation
- https://www.python.org/dev/peps/pep-0338/
- https://www.python.org/dev/peps/pep-0338/
- http://www.scotttorborg.com/python-packaging/command-line-scripts.html
- http://www.scotttorborg.com/python-packaging/command-line-scripts.html
- http://blog.habnab.it/blog/2013/07/21/python-packages-and-you/
- http://blog.habnab.it/blog/2013/07/21/python-packages-and-you/
1 个解决方案
#1
17
How can I use entry_points to generate a binary that calls python -m mypackage (and passes *args, **kwargs) ?
如何使用entry_points生成一个调用python -m mypackage(并传递*args、**kwargs)的二进制文件?
I think this is the wrong way to look at the problem. You don't want your script to call python -m mypackage
, but you want the script to have the same entry point as python -m mypackage
我认为这是看待问题的错误方式。您不希望脚本调用python -m mypackage,但希望脚本与python -m mypackage具有相同的入口点
Consider this simple example:
考虑一下这个简单的例子:
script_proj/
├── script_proj
│ ├── __init__.py
│ └── __main__.py
└── setup.py
and the minimalistic setup.py:
简约的setup . py:
from setuptools import setup
setup(
name="script_proj",
packages=["script_proj"],
entry_points = {
"console_scripts": [
"myscript = script_proj.__main__:main",
]
}
)
__main__.py
is a dummy module and contains the main
method.
__main__。py是一个虚拟模块,包含主要的方法。
def main():
print("Hello world!")
if __name__ == "__main__":
main()
After installing, you have the executable myscript
, which calls the main
method in __main__.py
. In this package design python -m script_proj
also calls the same main
method.
安装之后,您有了可执行的myscript,它调用__main__.py中的主方法。在这个包设计中,python -m script_proj也调用了相同的主方法。
#1
17
How can I use entry_points to generate a binary that calls python -m mypackage (and passes *args, **kwargs) ?
如何使用entry_points生成一个调用python -m mypackage(并传递*args、**kwargs)的二进制文件?
I think this is the wrong way to look at the problem. You don't want your script to call python -m mypackage
, but you want the script to have the same entry point as python -m mypackage
我认为这是看待问题的错误方式。您不希望脚本调用python -m mypackage,但希望脚本与python -m mypackage具有相同的入口点
Consider this simple example:
考虑一下这个简单的例子:
script_proj/
├── script_proj
│ ├── __init__.py
│ └── __main__.py
└── setup.py
and the minimalistic setup.py:
简约的setup . py:
from setuptools import setup
setup(
name="script_proj",
packages=["script_proj"],
entry_points = {
"console_scripts": [
"myscript = script_proj.__main__:main",
]
}
)
__main__.py
is a dummy module and contains the main
method.
__main__。py是一个虚拟模块,包含主要的方法。
def main():
print("Hello world!")
if __name__ == "__main__":
main()
After installing, you have the executable myscript
, which calls the main
method in __main__.py
. In this package design python -m script_proj
also calls the same main
method.
安装之后,您有了可执行的myscript,它调用__main__.py中的主方法。在这个包设计中,python -m script_proj也调用了相同的主方法。