PyTorch has deprecated official pre-built binaries (wheels) for macOS on Intel processors (x86_64) starting with version 2.3.0. The latest version with official support for your iMac is 2.2.2.
You may try to use an older, supported version. Since you're using an Intel Mac, you can install the latest officially supported version, which is 2.2.2. T
pip install torch==2.2.2
Or build it from scratch, but it's not an easy process.
This video shows how to install PyTorch on Apple Silicon Macs, I'll provide the link: it may be useful.