ImportError: cannot import name 'Tensor' from 'torch' (unknown location)
I’m trying to import Tensor
from PyTorch, but I keep getting this error:
ImportError: cannot import name 'Tensor' from 'torch' (unknown location)
Here’s the code causing the issue:
from torch import Tensor
What I’ve Tried:
- Checked that PyTorch is installed (
pip show torch
), and I’m using version2.5.1
. - Reinstalled PyTorch:
pip uninstall torch pip install torch
- Tested the import in a Python shell, but the error persists.
Environment:
- Python version: 3.10
- PyTorch version: 2.5.1
- OS: Windows 10
- Virtual environment: Yes
How can I fix this issue?