As stated in the error message, I think you should set the CUDA_TOOLKIT_ROOT_DIR environment variable.
Also, I would advise against using sudo to install pytorch as when you use it, you loose all the env variables that you have such as possibly LD_LIBRARY_PATH or other useful stuff.