Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Install PyTorch from requirements.txt

Torch documentation says use

pip install torch==1.4.0+cpu torchvision==0.5.0+cpu -f https://download.pytorch.org/whl/torch_stable.html

to install the latest version of PyTorch. This works when I do it manually but when I add it to req.txt and do pip install -r req.txt, it fails and says ERROR: No matching distribution.

Edit: adding the whole line from req.txt and error here.

torch==1.4.0+cpu -f https://download.pytorch.org/whl/torch_stable.html

torchvision==0.5.0+cpu -f https://download.pytorch.org/whl/torch_stable.htmltorch==1.4.0+cpu
ERROR: Could not find a version that satisfies the requirement torch==1.4.0+cpu (from -r requirements.txt (line 1)) (from versions: 0.1.2, 0.1.2.post1, 0.1.2.post2, 0.3.1, 0.4.0, 0.4.1, 1.0.0, 1.0.1, 1.0.1.post2, 1.1.0, 1.2.0, 1.3.0, 1.3.1, 1.4.0)
ERROR: No matching distribution found for torch==1.4.0+cpu (from -r requirements.txt (line 1))
like image 522
Siddharth Prajosh Avatar asked Mar 29 '20 10:03

Siddharth Prajosh


People also ask

Can I install PyTorch via pip?

To install PyTorch via pip, and do have a CUDA-capable system, in the above selector, choose OS: Linux, Package: Pip, Language: Python and the CUDA version suited to your machine. Often, the latest CUDA version is better. Then, run the command that is presented to you.

How do I download and install PyTorch?

To install PyTorch, you have to run the installation command of PyTorch on your command prompt. This command is available on https://pytorch.org/. Select language and cuda version as per your requirement. Now, run python -version, and Conda -version command to check Conda and python packages are installed or not.

Can I install PyTorch without CUDA?

You don't need to have cuda to install the cuda-enabled pytorch package but you need cuda to use it. We do not ship cuda with pytorch as it is a very big library.


2 Answers

Add --find-links in requirements.txt before torch

--find-links https://download.pytorch.org/whl/torch_stable.html

torch==1.2.0+cpu

Source: https://github.com/pytorch/pytorch/issues/29745#issuecomment-553588171

like image 169
Siddharth Prajosh Avatar answered Sep 20 '22 08:09

Siddharth Prajosh


-f https://download.pytorch.org/whl/torch_stable.html 
torch==1.4.0+cpu 
-f https://download.pytorch.org/whl/torch_stable.html
torchvision==0.5.0+cpu

worked fine for me :)

like image 35
n0obcoder Avatar answered Sep 18 '22 08:09

n0obcoder