python-3.x - OSError:file.so:无法打开共享对象文件:没有这样的文件或目录
问题描述
我已经构建了一个在我们的 python 包中使用的 .so 文件。我们在 Dietpi 64bits 上使用该软件包。当我导入我们的包时,我收到错误:
OSError: file.so: cannot open shared object file: No such file or directory
我知道文件在那里并且路径很好。
令我困惑的是,当我在虚拟机(也是 Diepi 64 位)上尝试相同的代码时,动态库被找到并正确加载。我这样做是为了尝试区分我的设置和我同事的设置之间的差异。
- 文件已存在
- 两种情况下的位置相同
- 文件具有相同的权限(chmod 777)
- 他正在使用 python 3.6,而 VM 3.7
我错过了什么?当目录确实存在并且文件存在时,什么会导致操作系统引发 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...
解决方案
我试图打开的共享库不是为您的虚拟机使用的体系结构构建的。
aarch64 与 x84_64
当我问这个问题时,我不知道我的目标(NanoPi Neo2)在构建共享库时需要与虚拟机不同的标志。
推荐阅读
- mysql - MYSQL 添加索引 - 不添加索引?
- git - 防止未经检查的更改合并到主分支
- jwt - 使用 auth0 身份验证登录公司网站重定向回登录
- typescript - 打字稿:省略不会警告额外的道具
- mitmproxy - 使用 mitmproxy UI 编辑多部分/表单数据时出现问题
- c# - 将 ObservableCollection 绑定到 ItemsControl
- jquery - 数据表从解析的 json 更改文本颜色
- maven - Apache cxf-codegen-plugin 未在 Spring Tool Suite 中生成 Java 存根
- python - 使用 python 托盘将 json 文件(3d 绘图)导入 ARCHICAD 24
- ruby-on-rails - 如何从 Rails 缓存哈希上传照片?