pypa / pypa/setuptools

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

Open
#309 10 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug major
Dominant language
Python
Stars
2.9k
Forks
1.4k
Avg merge
1d 1h
Merged PRs (30d)
1

Description

Originally reported by: floppym (Bitbucket: floppym, GitHub: floppym)


On Gentoo Linux, we are running into a problem building pyzmq with recent versions of setuptools.

https://bugs.gentoo.org/show_bug.cgi?id=532708

We get this error:

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

From what I can tell, it has to do with the order in which distutils.extenstion.Extension and setuptools are imported. setuptools replaces the Extension module with its own implementation. If this happens after setup.py has imported distutils.extension.Extension, it causes this problem.

Here is a reduced test case:

% cat setup.py
from distutils.core import setup
from distutils.extension import Extension
import setuptools

setup(ext_modules=[
        Extension('demo', ['demo.c'])
])
% python3.4 setup.py build
running build
running build_ext
error: each element of 'ext_modules' option must be an Extension instance or 2-tuple

The obvious workaround is to always import setuptools first. However, it is not always obvious where setuptools is being imported.

For pyzmq, it seems like setuptools is being imported indirectly; setup.py does not import it anywhere. By trial and error, it looks like importing nose brings in setuptools.


Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the reduced setup.py example with Python 3.4 and the reported setuptools import order. Then inspect how setup.py, pyzmq, and nose cause setuptools and distutils.extension.Extension to be imported, and verify that the build accepts ext_modules without the reported error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.