0

I'm trying to run a neural network from torch inside Java. I'm using luaj as a wrapper.

The problem is that when I require for example the torch module which depends on the libpaths module which is a shared library it throws the following error:

module 'libpaths' not found: libpaths
no field package.preload['libpaths']
libpaths.lua

Before I require any module I set the package.cpath and package.path to the folders where the libraries are because before it only looked in the default path which was just the project folder. However I have the feeling that 'require' only looks in the package.path for modules and not in the cpath because then it would also find libpaths.so. Also because this output includes only the directories from path and not cpath:

/home/erika/.luarocks/share/lua/5.1/libpaths.lua
/home/erika/.luarocks/share/lua/5.1/libpaths/init.lua
/home/erika/torch/install/share/lua/5.1/libpaths.lua
/home/erika/torch/install/share/lua/5.1/libpaths/init.lua
./libpaths.lua
/home/erika/torch/install/share/luajit-2.1.0-beta1/libpaths.lua
/usr/local/share/lua/5.1/libpaths.lua
/usr/local/share/lua/5.1/libpaths/init.lua

I tried package.searchpath() with the path from the cpath and 'libpath' and it did find the libpaths.so. I tried a lot of different things but nothing seems to work so I would really appreciate some help!

I use Lua 5.1.5, my OS is Ubuntu 14.04 LTS.

Adam B
  • 3,775
  • 3
  • 32
  • 42
erno.th
  • 11
  • 2

1 Answers1

2

When you're using luarocks to install packages locally, you should setup your environment before starting lua/luajit/torch. The easiest way is to execute the output of luarocks-5.1 path

$ luarocks-5.1 path
export LUA_PATH='/home/markus/.luarocks/share/lua/5.1/?.lua;/home/markus/.luarocks/share/lua/5.1/?/init.lua;/usr/share/lua/5.1/?.lua;/usr/share/lua/5.1/?/init.lua;./?.lua;/usr/lib/lua/5.1/?.lua;/usr/lib/lua/5.1/?/init.lua'
export LUA_CPATH='/home/markus/.luarocks/lib/lua/5.1/?.so;/usr/lib/lua/5.1/?.so;./?.so;/usr/lib/lua/5.1/loadall.so'

A more comfortable way is to put the output into your ~/.bashrc

$ luarocks-5.1 path >> ~/.bashrc

To reload your ~/.bashrc without logout and login, do source ~/.bashrc

Markus
  • 2,998
  • 1
  • 21
  • 28