python -m vs直接命令

时间:2019-01-19 01:59:05

标签: command-line setup.py python-3.7

我用setup.py编写了一段代码

entry_points = {'gui_scripts': ['mycode = mycode.__main__:main',],},

我希望能够使用命令mycode而不是python -m mycode来调用它

__main__.py以shebang #!/usr/bin/env python

开头

你知道怎么做吗?

(我在全新安装的Archlinux上使用python3.7)

1 个答案:

答案 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',],},
相关问题