Fixing "'module' object has no attribute 'which'" error on Python 3.1

As the function shutil.which has been added on Python 3.3, we need to duplicate
the implementation for older versions of Python 3.