我用setup.py编写了一段代码
entry_points = {'gui_scripts': ['mycode = mycode.__main__:main',],},
我希望能够使用命令mycode
而不是python -m mycode
来调用它
__main__.py
以shebang #!/usr/bin/env python
你知道怎么做吗?
(我在全新安装的Archlinux上使用python3.7)
答案 0 :(得分:1)
如果您“安装” Python模块,则可以执行此操作。
这些假设您仍然希望能够在本地计算机上的任何地方编辑代码:
# doing it in a non-global way (i.e., just for the current user)
# from the directory containing your "setup.py" file
pip install --user -e .
# and as long as ~/.local/bin is in your path:
mycode
如果要使其对计算机上的每个用户可用,
# install an "editable" copy of the code from the current directory
# into the global Python installation
pip install -e .
# this will install it next to pip and your other Python tools
mycode
请注意,您无需在setup.py中指定主要:
entry_points = {'gui_scripts': ['mycode = mycode:main',],},