torchscript
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_PATH
environment variable includes the thelib
directory of the unzipped package, such as/home/you/libtorch/lib
. The operating system will use this to load*.so
files and Java borrows it to set the value ofjava.library.path
.$ export LD_LIBRARY_PATH=/home/you/libtorch/lib`
-
Windows
Make sure the
PATH
environment variable includes thelib
directory of the unzipped package, such asD:\Users\you\libtorch\lib
. The operating system will use this to load*.dll
files 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_PATH
orDYLD_LIBRARY_PATH
variables and cannot use them to buildjava.library.path
or use them insbt
so that a torchscript program will run from there. The operating system uses the variables to find the*.dylib
files 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 dist
with 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 ...