在setup.py中运行自定义命令时出错

时间:2017-11-08 14:22:37

标签: python setuptools setup.py

我正在运行Python 3.6.3并且我一直在尝试向setup.py添加自定义命令。

据我所知,我所做的似乎与我在这个主题上看到的各种教程和示例相匹配,但我无法让它发挥作用。

我已将setup.py剥离到最低限度。这是:

import setuptools

class FooCommand(setuptools.Command):
    user_options = []

    """Custom build command."""

    def initialize_options(self):
        """Abstract method that is required to be overwritten"""

    def finalize_options(self):
        """Abstract method that is required to be overwritten"""

    def run(self):
        print("Running foo command...")

setuptools.setup(
    cmdClass={'foo': FooCommand}
)

当我运行python setup.py foo

我收到以下错误:

/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/distutils/dist.py:261: UserWarning: Unknown distribution option: 'cmdClass'
  warnings.warn(msg)
usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
   or: setup.py --help [cmd1 cmd2 ...]
   or: setup.py --help-commands
   or: setup.py cmd --help

error: invalid command 'foo'

1 个答案:

答案 0 :(得分:0)

我终于明白了。 cmdClass中有一个拼写错误。它应该是cmdclass - 即全部小写。

setuptools.setup(
    cmdClass={'foo': FooCommand}
)