Suraj:

Although the problem in my case is importing torch in a jupyter notebook. No error while running any script from the terminal but error shows up in importing torch in a jupyter notebook.


Most likely your Jupyter notebook is using a different Python kernel than the one used in the terminal.
You should be able to select the right Python kernel in the notebook directly.