This error seems to be caused by a variety of issues, which apparently point towards a broken installation as seen e.g. here 12.
Could you create a new virtual environment, reinstall PyTorch there, and rerun the code, please?