Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

I am trying to use setuptools in python to create an egg package, but I get this weird error:

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

How can I fix this?

like image 831
Human Avatar asked Feb 06 '14 05:02

Human


2 Answers

I had to reorder import statements to get rid of this error. This code generates the error:

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

This code does not generate the error:

from setuptools import find_packages, setup from Cython.Build import cythonize 
like image 154
klaus se Avatar answered Sep 22 '22 12:09

klaus se


Assuming that you already have setuptools installed, Edit setup.py of the egg package target and replace the import setup, Extension in order to get them from setuptools.

from setuptools import setup, Extension, Command 

Rational: setuptools redefines Extension so it's possible that it does not recognize the object that you have in the ext_modules argument as a valid Extension object. Hence the error message.

ext_modules is one of the arguments of setup() method that describe the extension of your module, and it's specified in setup.py.

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

More info available in Python documentation

like image 28
Farsee Avatar answered Sep 20 '22 12:09

Farsee