distutils setup.py 安装 - 'module' 对象不可调用

distutils setup.py install - 'module' object is not callable

我正在尝试使用特定的 python/numpy 库 rmcgibbo/logsumexp,但无法安装它。这是我按照说明 运行 setup.py install 时的轨迹:

$ python setup.py install
running install
running build
running build_ext
Traceback (most recent call last):
  File "setup.py", line 26, in <module>
    ext_modules = [ext]
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py", line 152, in setup
    dist.run_commands()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 953, in run_commands
    self.run_command(cmd)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/command/install.py", line 573, in run
    self.run_command('build')
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/cmd.py", line 326, in run_command
    self.distribution.run_command(command)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 972, in run_command
    cmd_obj.run()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/command/build.py", line 127, in run
    self.run_command(cmd_name)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/cmd.py", line 326, in run_command
    self.distribution.run_command(command)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 970, in run_command
    cmd_obj = self.get_command_obj(command)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py", line 846, in get_command_obj
    cmd_obj = self.command_obj[command] = klass(self)
TypeError: 'module' object is not callable

Contents of setup.py

可能是什么问题?

您正在导入 build_ext 模块,但未指定该模块中的可调用项。您真正想要做的是将 try 块中的内容更改为:

try:
    from Cython.Distutils.build_ext import build_ext
    src = ['sselogsumexp.pyx', 'src/logsumexp.c']
except ImportError:
    from distutils.command.build_ext import build_ext
    src = ['sselogsumexp.c', 'src/logsumexp.c']

我用 distutils.command.build_ext 模块测试了这个。如果您查看该模块,您会注意到有一个名为 build_ext 的 class,因此为了调用 'callable',您需要按照我的示例中的说明进行导入。我 运行 setup.py 更改了代码并且它起作用了。