You would get this error e.g. if your current working directory is inside the pytorch folder (after building from source), so make sure to open the Python terminal somewhere else.
Also, this might happen, if the installation was unsuccessful or if you have multiple pytorch installations in your current environment (although the error might look different).
How did you install PyTorch and could you create a new environment and reinstall it?