Install Torch7 using Lua5.2 on Ubuntu 18.0.4

This document files how to install Torch7:

  • On Ubuntu 18.0.4
  • Lua5.2
  • Cuda 10.1

本文将详细分析该协议的数据结构及迁移规则 (Murphi语言)

Official tutorial of torch 7 installation

Download Torch7 from github

1
git clone https://github.com/torch/distro.git ~/torch --recursive

Install dependencies

This step

1
2
cd ~/torch
bash install-deps

If error Package 'python-software-properties' has no installation candidate happens, then:

1
vim install-deps

and fine sudo apt-get install -y python-software-properties , comment it out by adding # before this line. Like this:

1
# sudo apt-get install -y python-software-properties

Save and exit.

Install Torch7

With Lua5.2

1
TORCH_LUA_VERSION=LUA52 ./install.sh

With Lua 5.1

1
TORCH_LUA_VERSION=LUA51 ./install.sh

Then, you need to refresh your environment variables by:

1
source ~/.bashrc

If failed

In general, run this script directly will fail, so I cite the solution below:

This script detects CUDA and attempts to install CUDA-specific lua extensions, but those installations fail because of the same GCC version issue discussed above.

To work around this, edit install.sh and comment out anything inside of conditionals which check if [ -x "$path_to_nvcc" ]: during initial installation.

[LINK]

After commenting out CUDA-specific lines, we can now install a non-CUDA-specific version.

Test installation success

Test torch

1
th

output:

1
2
3
4
5
6
7

______ __ | Torch7
/_ __/__ ________/ / | Scientific computing for Lua.
/ / / _ \/ __/ __/ _ \ | Type ? for help
/_/ \___/_/ \__/_//_/ | https://github.com/torch
| http://torch.ch

Then torch7 installed successfully.

Test luarocks

1
luarocks list

output what you have installed.

Then exit by exit .

Fully test

Run test.sh in ~/torch:

1
./test.sh

With gcc-6 and g++-6

Install cutorch

1
CC=gcc-6 CXX=g++-6 install/bin/luarocks install cutorch

Install cunn

1
CC=gcc-6 CXX=g++-6 install/bin/luarocks install cunn

Install cudnn

1
CC=gcc-6 CXX=g++-6 install/bin/luarocks install cudnn

Install torch

1
luarocks install torch

Install nn

1
luarocks install nn

Note that nn needs to be installed after torch.

Install nngraph

1
luarocks install nngraph

Install lua-cjson

There are some problems in cjson2.1.0.6-1, so you may want to avoid this version by specifying other version, such as:

1
luarocks install lua-cjson 2.1.0-1

(Link)

Install hdf5

1
2
3
4
sudo apt-get install libhdf5-serial-dev hdf5-tools
git clone https://github.com/deepmind/torch-hdf5
cd torch-hdf5
luarocks make hdf5-0-0.rockspec

When Ubuntu >13.04, run this command in the end.

1
LIBHDF5_LIBDIR="/usr/lib/x86_64-linux-gnu/"

(Link)

https://github.com/deepmind/torch-hdf5/pull/100/commits/539fc15ecd25b93f4d0784ea4eb75681329f9714

Some error cases

Error: No results matching query were found.

Please check your package name.

If you are not sure about it, please

If fail to use luarocks to install

and warning with url with ./cache/luarocks, then remove this direction

1
sudo rm -r [copy url here]

For example:

1
sudo rm -r /usr/.cache/luarocks/

If you want to check version of some packages

1
luarocks search lua-cjson

If fix: HDF5File.__init() requires a fileID

Follow this Link to modify the corresponding files.