Remove noisy messages from which command and deprecated functions.

1) Try to be compatible with python2 and 3
2) Replace os.system and os.popen calls with subprocess module
3) Remove which output by using also subprocess module