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.
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
Related
I've written a GUI in Java and use a lua-script to calculate some values for images with a neural network. Therefore the lua-script requires some modules from torch7.
I got so far that it finds the modules which have a init.lua file. However, it fails when a module only has a .so file. The module is required in one of the init.lua files.
Before I require the modules in the script i set the new package.path and the package.cpath to LUA_PATH and LUA_CPATH because luaj only used the default path which didn't work.
I think this a LuaJ problem because when I run the script in the terminal with lua script_name.lua it works fine.
package.path = package.path .. ';/home/user/.luarocks/share/lua/5.1
/?.lua;/home/user/.luarocks/share/lua/5.1/?/init.lua;/home/user/torch
/install/share/lua/5.1/?.lua;/home/user/torch/install/share/lua/5.1
/?/init.lua;./?.lua;/home/user/torch/install/share/luajit-2.1.0-
beta1/?.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1
/?/init.lua'
package.cpath = '/home/user/torch/install/lib/?.so;/home/user/.luarock
/lib/lua/5.1/?.so;/home/user/torch/install/lib/lua/5.1/?.so;./?.so;
/usr/local/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/loadall.so'
require 'torch'
require 'nn'
require 'image'
The error message is as follows:
exception in thread "main" org.luaj.vm2.LuaError: #/home/user/torch/install/share/lua/5.1/paths/init.lua:1 module 'libpaths' not found: libpaths
no field package.preload['libpaths']
libpaths.lua
/home/user/.luarocks/share/lua/5.1/libpaths.lua
/home/user/.luarocks/share/lua/5.1/libpaths/init.lua
/home/user/torch/install/share/lua/5.1/libpaths.lua
/home/user/torch/install/share/lua/5.1/libpaths/init.lua
./libpaths.lua
/home/user/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
no class 'libpaths'
I call the script from my java program:
public ScoreImage(){
G_ = JsePlatform.standardGlobals();
//G_.get("dofile").call( LuaValue.valueOf(changePath_));
G_.get("dofile").call( LuaValue.valueOf(script_));
}
I use lua 5.1 because some of the problems where solved by changing from lua 5.2 to lua 5.1. I have Ubuntu 14.04 LTS and luaj 3.0.1.
I really appreciate any help!
It seems that LuaJ does not have the ability to load dll files and so files.
You may want to look into jnlua:
https://code.google.com/archive/p/jnlua/
Compiled and installed ejabberd version 15.10 on ubuntu 14.04 machine in /opt/ejabberd directory.
In the older version the module can be compiled directly with erlc command and then pasted to ejabberd module dir(or symbolic linked) which was very efficent way to develop the modules.
But after upgrading to newer ejabberd version when using the INFO_MSG()/2 from logger.hrl the ejabberd fails to load the module.
When compiled by placing the module file inside the ejabberd src directory and running make in ejabberd directory as suggested at https://www.ejabberd.im/ejabberd-13.10 and ejabberd how to compile new module the module works.
But this is very inefficient compared to the older method of compiling and running the modules with elrc command directly.
Is the latter approach the right method, if so why was it changed and where are the official docs that explain compiling with latter approach.
you can compile ejabberd module like this
erlc -I /lib/ejabberd/include -o /lib/ejabberd/ebin /home/sunil/Documents/ejabberd_custom_modules/mod_profile.erl
In this example /lib/ejabberd/include is header file (.hrl) path , /lib/ejabberd/ebin* is binary file path of ejabberd and '/home/sunil/Documents/ejabberd_custom_modules/mod_profile.erl is source file path.
Right way to compile your custom ejabberd module (suggested by process-one) is :-
put your module into ejabberd/src folder.
come to ejabberd directory in terminal and run command $ sudo make
it will show you that your module is compiled. You can check ebin directory for .beam file that is result of your compilation.
Now to run your module
$ sudo make install
Add your module into config file at /etc/ejabberd/ejabberd.yml
restart your ejabberd and your custom module will be running.
Another way of compiling with erlang shell is :-
start your erlang to load all included files required by ejabberd module from ebin directory.
> erl -pa <your path to ejabberd/ebin>
You can also give multiple paths separated by space if you are including files from multiple places. Like
> erl -pa <path1/ebin> <path2/ebin>
This will start erlang shell. Next things you need to do are :-
do
> cd("<path to your module.erl file>").
compile your module
> c(your module).
Your module.beam file will be generated as a result of your compilation.
I am trying to require a module I downloaded using luarocks using
require "lualogging"
but lua (and I!) cannot find where this module was downloaded to. Here is what I did
I have used apt-get to install luarocks, and then I ran
sudo luarocks install lualogging
I then ran
luarocks list
and received the following output
Installed rocks:
lualogging
1.3.0-1 (installed) - /usr/local/lib/luarocks/rocks
luasocket
3.0rc1-1 (installed) - /usr/local/lib/luarocks/rocks
Natural this led me to believe that lualogging was located in /usr/local/lib/luarocks/rocks, but running this command
find /usr/local/lib/luarocks/rocks "lualogging.lua"
returned nothing. What am I doing wrong here? This may be related, but I cannot find what my LUA_PATH environment variable is so it may be that it was never set? I'd like to be able to run require "lualogging" from any file regardless of where it is located in the filesystem, and then log to my heart's content. But I can't even find where lualogging.lua exists...
Run luarocks show lualogging. It will list all modules and where they are.
It should be
require "logging"
not
require "lualogging"
In NodeJS/NPM, you can create a package.json and run npm install to install all your dependencies in a folder within your project: ./node_modules. (A project can be an app or another module/package.)
Ruby also has a "bundler" system (using a .bundle file) that keeps track of gems specific to a dir (ie project).
Does LuaRocks have similar conventions? Or is it recommeneded to install everything to /usr or $HOME?
So far I've been able to get similiar functionality, but I have to create a custom LuaRocks config file and specify --tree=my_local_lua_rocks_dir every time I want to install a rock. Granted, I can always create a bash script. The point is that it seems I'm going against a convention.
It is possible to install rocks into a directory under the current directory, using the --tree flag:
luarocks install --tree ./lua_modules lpeg
And then you have to configure your package.path and package.cpath variables in Lua (settable via LUA_PATH and LUA_CPATH environment variables) so it finds the modules installed inside it. There are several ways to do this conveniently: this tutorial explains how to do it, with more examples.
Instead of using Vert, I've decided to just edit the LuaRocks config file:
In /etc/luarocks/config.lua :
rocks_servers = {
[[http://rocks.moonscript.org/]],
[[http://luarocks.org/repositories/rocks]]
}
rocks_trees = {
[[/usr/local]],
[[./my_dir]]
}
./my_dir is relative to the pwd you're in, not to the location of the config file. Of course, change my_dir to whatever you want.
"The order of the rock_trees matters: When installing rocks, LuaRocks tries to pick a location to store the rock starting from the bottom of the list; when loading rocks in runtime, LuaRocks scans from the top of the list." From: http://luarocks.org/en/Config_file_format
Then in your .bashrc:
eval `luarocks path`
export PATH=$PATH:my_dir/bin
However, for certain commands you now have to specify the tree or it will give you a confusing error:
luarocks make --tree=my_dir
Generally, when a Perl module installs an executable script, it somehow changes the #!/usr/bin/perl line to point to the appropriate Perl path. For example, if I used the perl installed at /usr/local/bin/perl to install the module, then the shebang line will be changed to #!/usr/local/bin/perl, so that the installed script will always use the version of perl that installed it.
What does this, and how can I do it in my own modules that install scripts?
Edit
Note that I am specifically talking about executable perl scripts that are distributed as part of a Perl module. Since a module is installed to a specific version of Perl, any scripts installed by that module must use that same version, so #!/usr/bin/env perl is wrong.
From http://metacpan.org/pod/ExtUtils::MakeMaker
EXE_FILES
Ref to array of executable files. The files will be copied to the INST_SCRIPT directory. Make realclean will delete them from there again.
If your executables start with something like #!perl or #!/usr/bin/perl MakeMaker will change this to the path of the perl 'Makefile.PL' was invoked with so the programs will be sure to run properly even if perl is not in /usr/bin/perl.