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.

Regression for no attribute '__reduce_cython__' in Cython 0.29

See original GitHub issue

Platform: Windows 10 Python Version: 3.6.7

When running a program built with PyInstaller, cdef class types built with Cython 0.29 or later fail during extension module initialization with AttributeError: type object '<type>' has no attribute '__reduce_cython__'.

I can confirm that the fix in Cython 0.28.3-2.8.6 still works.

The program works without issue when run from Python instead of the PyInstaller bundle.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
carljmcommented, Sep 23, 2019

I have a pretty simple pure-Python and Cython repro of this problem. Using Cython 0.29.13, create this file cytest.pyx:

import doesnotexist

cdef class Foo:
    pass

Then after compiling it, run:

try:
    import cytest
except ImportError:
    pass

import cytest

Expected behavior is to see an ImportError from the attempt to import a nonexistent module. Actual behavior is that we see the __reduce_cython__ AttributeError instead, hiding the real error.

This is not just a toy example, it was simplified from a real-world Django application. When importing your INSTALLED_APPS, Django has code to catch ImportError and try to import again, treating the final component of the dotted path as an attribute instead of a submodule. We had an ImportError in unrelated code several layers deeper in the import stack from our Cython module, and Cython (in combination with Django’s re-importing behavior) replaced the ImportError with the __reduce_cython__ AttributeError on the second try, totally hiding the real ImportError and making it very difficult to debug. (Note that the failing import doesn’t have to be directly in the Cython module, as in the simplest-case above, it can be anywhere deeper in the import stack.)

0reactions
scodercommented, Apr 26, 2020

Closing as duplicate of #3545.

Read more comments on GitHub >

github_iconTop Results From Across the Web

'__reduce_cython__' error in Python while importing ...
I have Anaconda and I am a Jupyter Notebook user. I am unable to troubleshoot this error. AttributeError Traceback (most recent call last)...
Read more >
Type Object 'Pandas._Libs.Tslib._Tsobject' Has No Attribute ...
AttributeError: module 'pandas' has no attribute 'tslib' how to resolve this I am ... Regression for no attribute 'reducecython' in Cython 0.29 #2985....
Read more >
Cython 0.26 and Python 3 - Google Groups
After upgrading to Cython 0.26 from 0.25.2, I am now getting the following error at runtime with the ... AbelianGroup' has no attribute...
Read more >
Cython 0.29.14 - PyPI
The Cython compiler for writing C extensions for the Python language.
Read more >
Installing Cython — Cython 3.0.0a11 documentation
Installing Cython¶. Many scientific Python distributions, such as Anaconda [Anaconda], Enthought Canopy [Canopy], and Sage [Sage], bundle Cython and no ...
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