使用distutils.core时出现“错误:未提供命令”

时间:2019-11-05 19:05:50

标签: python distutils

我正在CentOS 7上使用Python3。我正在尝试构建here中所述的C扩展。我编写了一个简单的程序demo.c,它位于PYTHONPATH中的目录中。 demo.c具有以下格式。

#include <stdio.h>
#include <stdlib.h>

int main()
{
    printf("Hello from demo.c\n");
    return 0;
}

此代码运行无误。

from distutils.core import setup, Extension

module1 = Extension('demo',
                sources = ['demo.c'])

但是,以下代码

setup (name = 'PackageName',
   version = '1.0',
   description = 'This is a demo package',
   ext_modules = [module1])

产生以下错误。

An exception has occurred, use %tb to see the full traceback.

SystemExit: usage: CInterface.py [global_opts] cmd1 [cmd1_opts] [cmd2     [cmd2_opts] ...]
or: CInterface.py --help [cmd1 cmd2 ...]
or: CInterface.py --help-commands
or: CInterface.py cmd --help

error: no commands supplied

1 个答案:

答案 0 :(得分:1)

错误是说您需要传递Distutils命令,例如build (or probably build_ext in your case)

python CInterface.py build_ext