Requiring torch

758 views
Skip to first unread message

SomeGuy

unread,
May 2, 2012, 2:27:49 AM5/2/12
to torch7
Hi,

I'm having trouble importing torch in standard Lua, which I need to do
for integration with another app. I've installed torch at /usr/local/
bin/torch, so when I execute "$ /usr/local/bin/torch", I can just do
require 'torch'

and all is well. But when I do the same thing in regular Lua, it
can't find it. I just get the following:

$ lua
Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio
> require 'torch'
stdin:1: module 'torch' not found:
no field package.preload['torch']
no file './torch.lua'
no file '/opt/local/share/lua/5.1/torch.lua'
no file '/opt/local/share/lua/5.1/torch/init.lua'
no file '/opt/local/lib/lua/5.1/torch.lua'
no file '/opt/local/lib/lua/5.1/torch/init.lua'
no file './torch.so'
no file '/opt/local/lib/lua/5.1/torch.so'
no file '/opt/local/lib/lua/5.1/loadall.so'
stack traceback:
[C]: in function 'require'
stdin:1:

Note the following:
$ which torch
/usr/local/bin/torch
$ which lua
/opt/local/bin/lua

Any help appreciated. Do I need to install torch at /opt/local?

Thanks!

The Chemist

unread,
May 2, 2012, 10:19:12 AM5/2/12
to tor...@googlegroups.com
Well, we don't really support Torch7 with a regular Lua build. But you could get it to run by doing two things:

1/ in your Lua, set package.path and package.cpath to the ones that are in torch:
$ torch
> print(package.path)
...
> print(package.cpath)
...
$ lua
> package.path = ...
> package.cpath = ...

After that you can require 'torch' from Lua, it will find everything.

2/ But it will crash as soon as you make a function call in the torch library. 
The reason is that torch is built in c++ mode, and our lua, that's embedded in torch, as well.
A regular Lua is built in C, so there's a compat problem there. The way around is to rebuild
torch in C.

....

Torch has a bunch of complex dependencies, and I usually find it easier to build existing libraries
(socket, bitop, ...) against torch, and always use torch, instead of lua.

SomeGuy

unread,
May 2, 2012, 11:30:43 AM5/2/12
to torch7
Ouch.

I was thinking of using Torch to do some machine learning experiments
in an open source computer game (Battle for Wesnoth) which uses Lua,
but it would be completely infeasible, I think, to ask them to switch
over to using Torch's Lua.

Since Lua is heavily used in the gaming community and there is a fair
amount of research on using ML in gaming, I think you would get a lot
more customers if Torch was compatible with a standard Lua build.

The Chemist

unread,
May 10, 2012, 11:32:23 PM5/10/12
to tor...@googlegroups.com
Right, we used to be compatible with a plain Lua, and we should definitely keep supporting that.

We'll probably add that feature back in, soon.

Fulumstrom

unread,
Jul 23, 2012, 3:25:54 AM7/23/12
to tor...@googlegroups.com
I am a bit lost with this. I was hoping to develop something in Torch7, then add it in to a C program, and then I wanted to use interactive console to explore the running program. Is that how Torch is supposed to be used?
Reply all
Reply to author
Forward
0 new messages