Search code examples
bashdeep-learningtorchgoogle-colaboratory

How could I install Torch on Google Colab if it does not exist the file ~/.bashrc?


I want to install Torch (http://torch.ch/docs/getting-started.html#_) on Google Colab. However, to install Torch, we need to run the following command at the final step source ~/.bashrc

To run this command on google colab, the code I use is

%%bash
source ~/.bashrc

When I run those, I get a warning

bash: line 1: /content/.bashrc: No such file or directory

I also use this command to find bashrc

!find / -name '*bashrc'

And here is the output I get

/root/.bashrc

/etc/skel/.bashrc

/etc/bash.bashrc

/usr/share/base-files/dot.bashrc

/usr/share/doc/adduser/examples/adduser.local.conf.examples/skel/dot.bashrc

/usr/share/doc/adduser/examples/adduser.local.conf.examples/bash.bashrc

I try to run the source command on all of those paths. I also try the same with .profile. But the Torch still has not been installed.

EDIT: I'm not sure if Torch is installed or not. The specific problem here is that I just get an error

command not found

whenever I run th or luarocks


Solution

  • I set the required path and environment by python

    #for Torch with Lua 5.3:
    import os
    os.environ['LUA_PATH'] = '/root/.luarocks/share/lua/5.3/?.lua;/root/.luarocks/share/lua/5.3/?/init.lua;/root/torch/install/share/lua/5.3/?.lua;/root/torch/install/share/lua/5.3/?/init.lua;/root/torch/install/lib/lua/5.3/?.lua;/root/torch/install/lib/lua/5.3/?/init.lua;./?.lua;./?/init.lua'
    os.environ['LUA_CPATH'] ='/root/.luarocks/lib/lua/5.3/?.so;/root/torch/install/lib/lua/5.3/?.so;/root/torch/install/lib/lua/5.3/loadall.so;./?.so'
    os.environ['PATH'] += ':/root/torch/install/bin'
    
    if 'LD_LIBRARY_PATH' not in os.environ.keys():
      os.environ['LD_LIBRARY_PATH'] = ''
    else:
      os.environ['LD_LIBRARY_PATH'] += ':'
    os.environ['LD_LIBRARY_PATH'] +='/root/torch/install/lib'
    
    if 'DYLD_LIBRARY_PATH' not in os.environ.keys():
      os.environ['DYLD_LIBRARY_PATH'] = ''
    else:
      os.environ['DYLD_LIBRARY_PATH'] += ':'
    os.environ['DYLD_LIBRARY_PATH'] +='/root/torch/install/lib'
    
    if 'LUA_CPATH' not in os.environ.keys():
      os.environ['LUA_CPATH'] = ''
    else:
      os.environ['LUA_CPATH'] += ';'
    os.environ['LUA_CPATH'] += '/root/torch/install/lib/?.so'