Skip to content

Instantly share code, notes, and snippets.

@jubecker
Last active November 16, 2016 16:26
Show Gist options
  • Save jubecker/ba04b121933192c27f69 to your computer and use it in GitHub Desktop.
Save jubecker/ba04b121933192c27f69 to your computer and use it in GitHub Desktop.
Install torch7 on OS X 10.9

Install torch7 on OS X 10.9

The torch project: https://github.com/torch/torch7

Everything gets installed under /opt/lua

$ mkdir -p /opt/lua && sudo chown $USER /opt/lua

LuaJit http://luajit.org (2.0.3)

$ make PREFIX=/opt/lua/luajit install
$ ln -s /opt/lua/luajit/bin/luajit-2.0.3 /opt/lua/luajit/bin/lua

add /opt/lua/luajit/bin to $PATH

LuaRocks http://www.luarocks.org/ (2.1.2)

$ ./configure --with-lua=/opt/lua/luajit --prefix=/opt/lua/luarocks
$ make buid
$ make install

Change launch scripts /opt/lua/luarocks/bin/luarocks* to start like this:

#!/opt/lua/luajit/bin/lua
package.path = [[/opt/lua/luarocks/share/lua/5.1/?.lua;]]..package.path
...

Change config (/opt/lua/luarocks/etc/luarocks/config-5.1.lua) to look like this:

fs_use_modules = false

rocks_trees = {
   { name = [[user]], root = home..[[/.luarocks]] },
   { name = [[system]], root = [[/opt/lua/luarocks]] },
   { root="/opt/lua/luajit", bin_dir="/opt/lua/luajit/bin", lib_dir="/opt/lua/luajit/lib/lua/5.1"}
}

rocks_servers = {
   [[https://raw.github.com/torch/rocks/master]],
   [[http://luarocks.org/repositories/rocks]]
}

Patch LuaRocks to make it work with torch:

Edit /opt/lua/luarocks/share/lua/5.1/luarocks/fs/unix/tools.lua

Find line (~265) with ... vars.CURL.." -L and change it to vars.CURL.." -k -L to make curl accept all SSL certificates

Edit /opt/lua/luarocks/share/lua/5.1/luarocks/manif.lua

Find line (~117) with "manifest-"..cfg.lua_version..".zip", and remove it

Add /opt/lua/luarocks/bin to $PATH

Make LuaRocks findable by luajit:

$ ln -s /opt/lua/luarocks/share/lua/5.1/luarocks /opt/lua/luajit/share/lua/5.1/luarocks 

Install binary via DMG

Install torch rocks

$ luarocks install sundown
$ luarocks install cwrap
$ luarocks install paths
$ luarocks install torch
$ luarocks install nn
$ luarocks install dok
$ luarocks install gnuplot
$ luarocks install qtlua
$ luarocks install qttorch
$ luarocks install luafilesystem
$ luarocks install penlight
$ luarocks install sys
$ luarocks install xlua
$ luarocks install image
$ luarocks install optim
$ luarocks install lua-cjson
$ luarocks install trepl

Optional rocks which are not required for basic torch7 stuff:

$ mkdir build && cd build
$ cmake -G "Unix Makefiles" -D CMAKE_INSTALL_PREFIX=/Users/$USER/Library/Developer/opencv/ -D CMAKE_OSX_ARCHITECTURES=x86_64 -D BUILD_PERF_TESTS=OFF -D BUILD_opencv_legacy=YES -D WITH_CUDA=OFF ..
$ make -j8
$ make install

then

$ OpenCV_DIR="/Users/$USER/Library/Developer/opencv" luarocks install camera

Got only black images from the cam. Looks like a bug on OS X. Fix: clementfarabet/lua---camera#11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment