It’s hard to tell, if the issue might be CPU or OS - dependent (or might be triggered by any other issue).
What is concerning is that the previous issue was apparently solved after using the terminal instead of Jupyter, your local environment might also be “broken”.
Could you create a new virtual environment, reinstall PyTorch, and rerun the script?
If that doesn’t help, could you try to execute your script on Colab, which would use a notebook, but should use a Linux-based OS, if I’m not mistaken.