LaurentMazare / tch-rs

Rust bindings for the C++ api of PyTorch.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

load shared libraries: libtorch_cpu.so at runtime error

dupeiran001 opened this issue · comments

When creating a new binary project, which contains only a minimal main:

use tch::Tensor;

fn main() {
    let t = Tensor::from_slice(&[3, 1, 4, 1, 5]);
    let t = t * 2;
    t.print();
}

It panic at runtime with error:

    Finished dev [unoptimized + debuginfo] target(s) in 0.03s
     Running `target/debug/table-extractor`
target/debug/table-extractor: error while loading shared libraries: libtorch_cpu.so: cannot open shared object file: No such file or directory

seems like a dynamic linking error? Or maybe it has linked to a wrong libtorch?

I'm using libtorch version 2.1.0+cpu and tch version: tch = "0.14.0"

I've my libtorch in dir:LIBTORCH=/home/dpr/Develop/ML/libtorch/, whose tree structure are as follows

libtorch
    /lib
    /include
    /bin
    /share

and the lib subdir contains follow dynlibs:

image

and here is my output of envs:

HOSTTYPE=x86_64
LANG=en_US.UTF-8
PATH=/home/dpr/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/mnt/c/Program Files/PlasticSCM5/server:/mnt
/c/Program Files/PlasticSCM5/client:/mnt/c/Program Files/Zulu/zulu-17/bin/:/mnt/c/Windows/system32:/mnt/c/Windows:/mnt/c/Windows/System32/Wbem:/mnt/c/Windows/System32/WindowsPo
werShell/v1.0/:/mnt/c/Windows/System32/OpenSSH/:/mnt/c/Program Files/Git/cmd:/mnt/c/Program Files/nodejs/:/mnt/c/Program Files/zig-windows-x86_64-0.12.0-dev.21+ac95cfe44:/mnt/c
/Program Files/MariaDB 11.0/bin:/mnt/c/Program Files/Docker/Docker/resources/bin:/mnt/c/Program Files/dotnet/:/mnt/c/Program Files/Tesseract-OCR:/mnt/c/Program Files/MySQL/MySQ
L Shell 8.0/bin/:/mnt/c/Users/20838/.cargo/bin:/mnt/c/Users/20838/AppData/Local/Microsoft/WindowsApps:/mnt/c/Program Files/JetBrains/IntelliJ IDEA Community Edition 2023.2/bin:
/mnt/c/Users/20838/AppData/Local/Programs/Microsoft VS Code/bin:/mnt/c/Users/20838/AppData/Roaming/npm:/mnt/c/Program Files (x86)/apache-maven-3.9.4/bin:/mnt/c/ghcup/bin:/mnt/c/Users/20838/.dotnet/tools:/mnt/c/Users/20838/anaconda3/condabin:/home/dpr/.local/bin
TERM=xterm-256color
XDG_RUNTIME_DIR=/run/user/1000/
DISPLAY=:0
WAYLAND_DISPLAY=wayland-0
PULSE_SERVER=unix:/mnt/wslg/PulseServer
WSL2_GUI_APPS_ENABLED=1
WSLENV=
WSL_INTEROP=/run/WSL/447720_interop
NAME=LAPTOP-0F8O2SNI
HOME=/home/dpr
USER=dpr
LOGNAME=dpr
SHELL=/bin/zsh
WSL_DISTRO_NAME=Ubuntu-22.04
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
SHLVL=1
PWD=/home/dpr/Develop/ML/table-extractor
:*.esd=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.webp=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:
LIBTORCH=/home/dpr/Develop/ML/libtorch
VIRTUAL_ENV_DISABLE_PROMPT=12
_=/usr/bin/env

It seems that the shared library is not found, you can either add the path to the directory containing the .so files to the LD_LIBRARY_PATH environment variable, or copy the build.rs file from diffusers-rs or another example (which will set the rpath on your binaries to the directory used at compile time).
https://github.com/LaurentMazare/diffusers-rs/blob/f19c33f84599eb7dea3a65e5b0810ea55c4c57c3/build.rs#L1

Thank you, setting environment variable worked for me!!