简体   繁体   中英

Python: Invalid ELF header importing cython compiled library

My problem is the following. I'm working on Ubuntu and have a cython code which I compile using the following:

from distutils.core import setup
from Cython.Build import cythonize
import numpy

setup(
   ext_modules = cythonize("cython_accelerate.pyx"),
   include_dirs = [numpy.get_include()]
) 

Compilation works fine. When I try to import the generated library (cython_accelerate.so) I get the following error:

invalid ELF header.

If I do the exactly same procedure on Mac everything works perfectly: the only difference is that the library is generated with a different name (cython_accelerate.cpython-35m-darwin.so) but import works as expected without issues.

What am I doing wrong?

I'm working on Ubuntu

This is a rather meaningless statement. Probably you are using Ubuntu on x86_64 system.

If so, your problem is most likely due to 32-bit vs. 64-bit mismatch: you are trying to import 32-bit cython_accelerate.so into 64-bit Python process, or vice versa.

To verify this is the cause, run

file `which python`
file /path/to/cython_accelerate.so

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM