How to install pytorch CPU in requirements.txt?

We can install pytorch’s CPU version via pip install torch==2.1.1 --index-url https://download.pytorch.org/whl/cpu.

How can I add this to requirements.txt so I can install CPU version of it using pip install -r requirements.txt?

This is more Python than PyTorch, but you can either use --index-url (but this is global, so a bit tricky for requirements.txt) or give specific packages (whl archives) with @.

Best regards

Thomas

Here are the details:
https://pip.pypa.io/en/stable/reference/requirements-file-format/

1 Like

Thanks a lot, torch @ format worked well!