To run the Python programs, it should suffice to install the Python distribution of PyTorch from pytorch.org. Choose, for example, the stable build, your operating system, Conda or Pip, Python, and CPU. It appears that setting the LD_LIBRARY_PATH as described in the next paragraph will interfere with Python operations, so avoid it or turn it off for the Python programs.
To run the Java or Scala programs, you need to have the libraries installed and accessible. At pytorch.org choose, for example, the stable build, your operating system, LibTorch, C++/Java, and CPU. Download the packange and unzip the file on your hard drive.
-
Linux
Make sure the
LD_LIBRARY_PATHenvironment variable includes the thelibdirectory of the unzipped package, such as/home/you/libtorch/lib. The operating system will use this to load*.sofiles and Java borrows it to set the value ofjava.library.path.$ export LD_LIBRARY_PATH=/home/you/libtorch/lib`
-
Windows
Make sure the
PATHenvironment variable includes thelibdirectory of the unzipped package, such asD:\Users\you\libtorch\lib. The operating system will use this to load*.dllfiles and Java borrows it to set the value ofjava.library.path.For the regular command prompt it might look like
> set PATH=D:\Users\you\libtorch\lib;%PATH%
and for PowerShell like this:
PS> $env:PATH="D:\Users\you\libtorch\lib;" + $env:PATH
-
Mac
This is problematic. Java apparently and maybe officially does not have access to the
LD_LIBRARY_PATHorDYLD_LIBRARY_PATHvariables and cannot use them to buildjava.library.pathor use them insbtso that a torchscript program will run from there. The operating system uses the variables to find the*.dylibfiles and Java borrows them to set the value ofjava.library.path. So far the only way the example program has worked is by being called directly from Java aftersbt distwith all the aforementioned variables having been set manually.$ export LD_LIBRARY_PATH=/home/you/libtorch/lib $ export DYLD_LIBRARY_PATH=/home/you/libtorch/lib $ java -Djava.library.path=/home/you/libtorch/lib ...