【问题标题】:error: each element of 'ext_modules' option must be an Extension instance or 2-tuple错误:“ext_modules”选项的每个元素必须是扩展实例或 2 元组
【发布时间】:2014-03-02 22:15:25
【问题描述】:

我正在尝试在 python 中使用 setuptools 创建一个 egg 包,但我收到了这个奇怪的错误:

error: each element of 'ext_modules' option must be an Extension instance or 2-tuple

我该如何解决这个问题?

【问题讨论】:

标签: python setuptools


【解决方案1】:

如果您使用的是find_packages,请确保不要使用distutilssetuptools 的组合。此命令产生错误:

from distutils.core import setup, Extension
from setuptools import find_packages
from Cython.Build import cythonize

所以你应该使用setuptoolsfind_packages的实现:

from setuptools import find_packages, setup, Extension
from Cython.Build import cythonize

【讨论】:

    【解决方案2】:

    我不得不重新排序导入语句以消除此错误。此代码生成错误:

    from Cython.Build import cythonize
    from setuptools import find_packages, setup
    

    此代码不会产生错误:

    from setuptools import find_packages, setup
    from Cython.Build import cythonize
    

    【讨论】:

      【解决方案3】:

      发生这种情况是由于与 distutils 冲突,从哪里导入扩展 w.r.t setuptools。我在安装 gdsCAD 时看到了这个错误,所以我必须更新 setupext.py 才能成功安装

      【讨论】:

        【解决方案4】:

        假设您已经安装了 setuptools, 编辑 egg 包目标的 setup.py 并替换 import setup, Extension 以便从 setuptools 中获取它们。

        from setuptools import setup, Extension, Command
        

        Rational:setuptools 重新定义了Extension,因此它可能无法将您在 ext_modules 参数中的对象识别为有效的扩展对象。因此出现错误消息。

        ext_modules 是 setup() 方法的参数之一,用于描述模块的扩展,它在 setup.py 中指定。

        setup(name='foo',
          version='1.0',
          ext_modules=[Extension('foo', ['foo.c'])],
          ) 
        

        More info available in Python documentation

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2023-02-15
          • 2020-08-19
          • 2018-04-02
          • 2017-04-29
          • 1970-01-01
          • 1970-01-01
          • 2019-11-28
          • 2021-11-14
          相关资源
          最近更新 更多