1. Python CFFI
  2. Untitled project
  3. cffi
Issue #29 resolved

CFFI attempts to load .py cache file as ELF when extension is installed

Leonard Ritter
created an issue

I'm running across a strange error when running cffi with pypy, after installing my lib pystbimage with "pypy setup.py install" (develop mode works fine). I have seen this error on windows before, and thought it's platform related, but apparently this seems to be some kind of typo - either on CFFI's or my side:

{{{

Traceback (most recent call last): File "app_main.py", line 51, in run_toplevel File "/home/lritter/devel/duangle/beigedemo-0.2/lib-python/2.7/runpy.py", line 162, in _run_module_as_main "main", fname, loader, pkg_name) File "/home/lritter/devel/duangle/beigedemo-0.2/lib-python/2.7/runpy.py", line 72, in _run_code exec code in run_globals File "/home/lritter/devel/duangle/beigedemo-0.2/site-packages/beige-0.1-py2.7.egg/beige/runtime.py", line 26, in <module> from .engine import GLEngine File "/home/lritter/devel/duangle/beigedemo-0.2/site-packages/beige-0.1-py2.7.egg/beige/engine/init.py", line 21, in <module> from . import texture File "/home/lritter/devel/duangle/beigedemo-0.2/site-packages/beige-0.1-py2.7.egg/beige/engine/texture.py", line 10, in <module> from stbimage import stbi_load, stbi_flip_y #@UnresolvedImport File "/home/lritter/devel/duangle/beigedemo-0.2/site-packages/pystbimage-0.1-py2.7-linux-i686.egg/stbimage/init.py", line 5, in <module> from ._stbimage import * File "/home/lritter/devel/duangle/beigedemo-0.2/site-packages/pystbimage-0.1-py2.7-linux-i686.egg/stbimage/_stbimage.py", line 56, in <module> _LIB = load_lib(""" File "/home/lritter/devel/duangle/beigedemo-0.2/site-packages/pystbimage-0.1-py2.7-linux-i686.egg/stbimage/internal.py", line 31, in load_lib """, include_dirs = [CDEF_PATH]) File "/home/lritter/devel/duangle/beigedemo-0.2/site-packages/cffi-0.3-py2.7.egg/cffi/api.py", line 281, in verify return self.verifier.load_library() File "/home/lritter/devel/duangle/beigedemo-0.2/site-packages/cffi-0.3-py2.7.egg/cffi/verifier.py", line 62, in load_library return self._load_library() File "/home/lritter/devel/duangle/beigedemo-0.2/site-packages/cffi-0.3-py2.7.egg/cffi/verifier.py", line 134, in _load_library return self._vengine.load_library() File "/home/lritter/devel/duangle/beigedemo-0.2/site-packages/cffi-0.3-py2.7.egg/cffi/vengine_gen.py", line 47, in load_library module = backend.load_library(self.verifier.modulefilename) OSError: cannot load '/home/lritter/devel/duangle/beigedemo-0.2/site-packages/pystbimage-0.1-py2.7-linux-i686.egg/_cffig4a7105fbx2e813128.py': /home/lritter/devel/duangle/beigedemo-0.2/site-packages/pystbimage-0.1-py2.7-linux-i686.egg/_cffig4a7105fbx2e813128.py: invalid ELF header }}}

My setup.py (https://bitbucket.org/duangle/pystbimage/src/tip/setup.py) doesn't look particularly odd, so I wonder what could be wrong here?

Comments (9)

  1. Armin Rigo
    _cffi__g4a7105fbx2e813128.py
    

    Who comes up with such a name in the first place? I thought that the name prefix "_cffi_*" was only used with the extensions ".c" or ".so". It doesn't make sense with the extension ".py"...

  2. Armin Rigo

    What is in this file in the first place? Maybe it's some egg magic that replaces .so files with .py files that locate and load the .so? In other words, can you paste the content of this .py file?

    Such magic is bound to break obscure cases (like the one here, but not only). Well, you never know. I would be surprized if there was such magic, but after all it would just be yet another over-the-top behavior of installing schemes of Python :-(

  3. Armin Rigo

    Ok, found out that you need (as a workaround) to put the following line in your setup.py, as an extra argument to the setup() function:

    zip_safe=False,
    
  4. Leonard Ritter reporter

    This is what's in the file (you probably have seen this already)

    def __bootstrap__():
       global __bootstrap__, __loader__, __file__
       import sys, pkg_resources, imp
       __file__ = pkg_resources.resource_filename(__name__,'_cffi__g4a7105fbx2e813128.pypy-19.so')
       __loader__ = None; del __bootstrap__, __loader__
       imp.load_dynamic(__name__,__file__)
    __bootstrap__()
    

    Adding the zip_safe=False argument did not change anything for pypy - leaving it out also made no change; it's still creating the fake importer.

  5. Log in to comment