python -m vs 直接命令
python -m vs direct command
我写了一段代码 setup.py
entry_points = {'gui_scripts': ['mycode = mycode.__main__:main',],},
我希望能够使用命令 mycode
而不是 python -m mycode
来调用它
__main__.py
从 shebang 开始 #!/usr/bin/env python
你知道怎么做吗?
(我在全新安装的 Archlinux 上使用 python3.7)
如果您 "install" 您的 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 中指定 main:
entry_points = {'gui_scripts': ['mycode = mycode:main',],},
我写了一段代码 setup.py
entry_points = {'gui_scripts': ['mycode = mycode.__main__:main',],},
我希望能够使用命令 mycode
而不是 python -m mycode
__main__.py
从 shebang 开始 #!/usr/bin/env python
你知道怎么做吗?
(我在全新安装的 Archlinux 上使用 python3.7)
如果您 "install" 您的 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 中指定 main:
entry_points = {'gui_scripts': ['mycode = mycode:main',],},