Search code examples
pythonubuntushared-librariespython-import

importing .so file in python


this has been asked a million times but, after having tried all I found, I am still getting an ImportError. So, I am doing this:

import sys

sys.path.append("/usr/local/lib")

import libIpxCameraApiPy # I've tried libIpxCameraApiPy.so as well

And I get:

ImportError: /usr/local/lib/libIpxCameraApiPy.so: cannot open shared object file: No such file or directory

I should mention that:

  1. There is indeed a file named libIpxCameraApiPy.so in /usr/local/lib/
  2. If I do cat /etc/ld.so.conf.d/libc.conf I get

# libc default configuration

/usr/local/lib

  1. I have also tried export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH and ldconfig.

  2. I have actually been able to make this work on different pc before, just by pasting this file into "/usr/local/lib" as I did this time, and nothing else was needed.

Any help to get this import working will be appreciated.


Solution

  • ImportError: /usr/local/lib/libIpxCameraApiPy.so: cannot open shared object file: No such file or directory

    file /usr/local/lib/libIpxCameraApiPy.so /usr/local/lib/libIpxCameraApiPy.so: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, BuildID[sha1]=2934dfd0eedd2446bc661e09a4daf9fe31e7ced1, not stripped

    You are either trying to load a 64-bit library into 32-bit Python, or you are trying to load an x86_64 library into an aarch64 binary.

    is it possible that .so files need to be recompiled from source code when moving from a x86_64 pc with ubuntu 16 to an aarch64 with ubuntu 22?

    It's not "possible", it's definitely necessary: no binary from x86_64 system will run on an aarch64 system (and vice versa) -- they are completely different processors with completely different and incompatible instruction sets.