如果这不是发布此内容的最佳位置,我们深表歉意。
我正在尝试学习如何在 Rust 中使用 Pytorch。具有使用 C++ 中的 Libtorch 和 Python 中的 Pytorch 的经验。我在设置安装时遇到问题,并且不确定原因。
我首先尝试下载当前的 Libtorch,然后尝试链接它。我正在使用这些 Rust 绑定 https://github.com/LaurentMazare/tch-rs .
我将以下内容添加到我的 .bashrc 文件中:
export LIBTORCH=/home/me/libtorch/
export LIBTORCH_INCLUDE=/home/me/libtorch/
export LIBTORCH_LIB=/home/me/libtorch/
然后我将依赖项添加到我的 Cargo.toml 中,并且
cargo build
有效cargo run
导致
Finished dev [unoptimized + debuginfo] target(s) in 0.03s
Running `target/debug/torch_test`
target/debug/torch_test: error while loading shared libraries: libtorch_cpu.so: cannot open shared object file: No such file or directory
查看/home/me/libtorch/lib/下确实有一个libtorch_cpu.so文件。
知道为什么会失败吗?我很沮丧,因为我非常渴望尝试 Rust ML 项目想法,但不能。
我还安装了 Pytorch,并尝试做(在 .bashrc 中)
export LIBTORCH_USE_PYTORCH=1
所以它会使用 Pytorch 安装而不是手动下载的 Libtorch 文件,但令人困惑的是,它给出了相同的错误?要么只查看 Python 库,要么链接通常很混乱。
更新了我的 Fedora 安装、conda 和其他依赖项等。安装了最新的货物。
将
/home/me/libtorch/lib/
添加到 LD_LIBRARY_PATH 变量确实做了一些事情,但现在我收到错误
target/debug/torch_test: symbol lookup error: target/debug/torch_test: undefined symbol: _ZN3c106detail23torchInternalAssertFailEPKcS2_jS2_RKSs
解决了,感谢 Reddit 上的评论和浏览 Pytorch 论坛。
解决方案是:
LD_LIBRARY_PATH
。undefined symbol
错误。