首页 > 解决方案 > OSError:file.so:无法打开共享对象文件:没有这样的文件或目录

问题描述

我已经构建了一个在我们的 python 包中使用的 .so 文件。我们在 Dietpi 64bits 上使用该软件包。当我导入我们的包时,我收到错误:

OSError: file.so: cannot open shared object file: No such file or directory

我知道文件在那里并且路径很好。

令我困惑的是,当我在虚拟机(也是 Diepi 64 位)上尝试相同的代码时,动态库被找到并正确加载。我这样做是为了尝试区分我的设置和我同事的设置之间的差异。

我错过了什么?当目录确实存在并且文件存在时,什么会导致操作系统引发 No such file or directory 异常?


编辑

这是我正在使用的代码

import os
import ctypes

shared_library_name = "libFoo"

print("current working directory: {}\n".format(os.getcwd()))
current_path = str(os.path.dirname(os.path.abspath(__file__)) + "/natives/")
os.chdir(current_path)
current_path = os.path.abspath(os.getcwd())

path_to_so = os.path.abspath(current_path + "/" + shared_library_name + ".so")
print("new current_path: ", current_path)
print("\n path_to_so: {}\n".format(path_to_so))
# prints the right path with the right file, and I can cd to it in the terminal

print("path exist {}".format(os.path.isdir(current_path)))
print("file exist {}\n".format(os.path.isfile(path_to_so)))
# prints False

dll = ctypes.cdll.LoadLibrary(path_to_so)
# fails saying that the file is not there...

标签: python-3.xlinux

解决方案


我试图打开的共享库不是为您的虚拟机使用的体系结构构建的。

aarch64 与 x84_64

当我问这个问题时,我不知道我的目标(NanoPi Neo2)在构建共享库时需要与虚拟机不同的标志。

https://unix.stackexchange.com/questions/461179/what-is-the-difference-between-differ-implemetation-of-arm64-aarch64-for-lin

arm64和aarch64的区别


推荐阅读