&quot“ Importerror: *.so:无法打开共享对象文件” PIP安装使用Pybind11构建的扩展模块
我遇到了一些我不了解的特殊行为。我有一个使用pybind11构建的python/c ++模块(称为x)。在我的构建目录中,
build
|- X
|- a.so
|- b.so
|- X.cpython-38-x86_64-linux-gnu.so (which depends on a.so and b.so)
当我在构建目录中时,python -c“ import x”
工作,这很棒。
然后,我为我的模块生成了一个WHL文件,然后将其安装在Virtualenv中,因此我在〜/venv/lib/python3.8/site-packages/x
中安装了上面的相同文件。 。但是,python -c“导入x”
然后导致“ Importerror:a.so:无法打开共享对象文件:否此类文件或目录”,因此大概是x.cpython*。因此,加载了
,但是OS不知道在哪里加载依赖的.so
files(a.so,b.so
)。
作为解决方法,我设置了ld_library_path =〜/venv/lib/python3.8/site-packages/x
,它解决了问题,但我认为这不是正确的方法。有人可以阐明为什么会发生这种情况以及解决它的正确方法吗?
I'm running into some peculiar behavior that I don't understand. I have a python/C++ module (call it X) built using pybind11. In my build directory I have
build
|- X
|- a.so
|- b.so
|- X.cpython-38-x86_64-linux-gnu.so (which depends on a.so and b.so)
When I'm in my build directory, python -c "import X"
works, which is great.
Then, I generated a whl file for my module, and pip installed it in my virtualenv, so I have the same files above installed in ~/venv/lib/python3.8/site-packages/X
. However, python -c "import X"
then resulted in "ImportError: a.so: cannot open shared object file: No such file or directory", so presumably the X.cpython*.so
was loaded, but the OS doesn't know where to load the dependent .so
files (a.so, b.so
).
As a workaround, I set LD_LIBRARY_PATH=~/venv/lib/python3.8/site-packages/X
, and it resolves the issue, but I don't think that's the proper way. Can someone shed some light on why this is happening and the proper way to resolve it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅在这里及其中的引用。在这种情况下
See here and references therein. In this case you will want to add
-Wl,-rpath,$ORIGIN
to the extra linker arguments when defining your extension e.g.