Simone Bolognini
Simone Bolognini

Reputation: 524

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?

Upvotes: 0

Views: 2842

Answers (1)

Employed Russian
Employed Russian

Reputation: 213646

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

Upvotes: 1

Related Questions