question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to Ignore Cython, even if found

See original GitHub issue

Currently, importing setuptools.command.build_ext pulls in a Cython dependency if it finds any Cython on a system.

That is not in all cases ideal, e.g. in a package manager (such as spack) or a virtual python environment that does not have a cython installed, while at the same time a system-wide Cython exists. In such a setup, nearly always binary incompatibilities with the system-wide python install will occur.

Is there any way to express “try not to import cython (even when found)” to setuptools?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jaracocommented, Jan 8, 2018

@ax3l: I don’t. I’d suggest starting with the mailing list or maybe file an issue with their tracker to explain the issue and get advice on how to proceed.

1reaction
jaracocommented, Dec 7, 2017

Thanks @ax3l for the reproducer. I’ve uploaded it as this gist. I then made a couple of revisions. The first was to specify a base image, which I suspect was necessary because I’m testing on macOS. At that point, I was able to run the build and get the error you described.

But I noticed one thing - that you’re not in fact installing Cython system-wide; you’re installing it in the user site (pip install --user). And the way user-local works is it’s shared across different Python installs… which clarifies the answer to the question, how is import cython succeeding.

In the next revision, I installed Cython system-wide, and the issue goes away. Now that Cython is installed only to the system Python 2.7, it no longer appears in the miniconda install of Python 2.7, and all is well.

In rev 4, I took another tack and disabled that user-local environment before invoking the build. This also bypasses the issue. One could alternatively have set PYTHONNOUSERSITE=1.

I think this demonstrates that the issue originates from an incorrect usage of user-local environments and presents a couple of plausible workarounds.

I do sympathize with the issue and thinking about the presented workaround in Setuptools, I’m reluctant to go with that approach because of the complexity of behavior it adds on import. If on the other hand cython has or could add a call to check that it’s viable in this environment, like cython.assert_viable(), that is something I would be willing to add, something like:

try:
    # Attempt to use Cython for building extensions, if available
    from Cython.Distutils.build_ext import build_ext as _build_ext
    __import__('cython').assert_viable()
except (ImportError, AssertionError):
    _build_ext = _du_build_ext

In other words, if Cython is willing to support this use-case, then setuptools will support it as well.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I disable Cython? - python - Stack Overflow
Use following command to find the package rpm -qa |grep cython. Then if found then copy past your package name in this command...
Read more >
How to ignore the annoying Cython warnings in PyPy 6.0
1: if you compile it you still get the warning, even if you locally installed a newer version of Cython. There is not...
Read more >
Pure Python Mode — Cython 3.0.0a11 documentation
This is accomplished via an augmenting . pxd file, via Python type PEP-484 type annotations (following PEP 484 and PEP 526), and/or via...
Read more >
How to find out where an AttributeError is ignored
the problem? So far, I don't even know in what file the error is ignored. ... was ignored, but Cython does not reveal...
Read more >
"Modern" way to build packages with C (Cython) extensions
Regarding setuptools docs specifically, if you find any ... SciPy is working to make cython more compatible with meson , but it is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found