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

时间:2015-09-17 10:29:22

标签: python distutils setup.py

我正在尝试使用特定的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

问题是什么?

1 个答案:

答案 0 :(得分:3)

您正在导入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的类,因此为了调用可调用的&#39;,您需要按照我的示例中的指定导入。我使用代码更改运行了setup.py并且它运行了。