'How to specify pytorch / cuda version in pipenv
I am trying to install a specific version of pytorch that is compatible with a specific cuda driver version with pipenv. The pytorch website shows how to to this with pip:
pip3 install torch==1.3.1+cu92 torchvision==0.4.2+cu92 -f https://download.pytorch.org/whl/torch_stable.html
I tried to convert this into an entry in my Pipfile like this:
[[source]]
name = "pytorch"
url = "https://download.pytorch.org/whl/torch_stable.html"
verify_ssl = false
pytorch = {version="==1.3.1+cu92", index="pytorch"}
torchvision = {version="==0.4.2+cu92", index="pytorch"}
However, this does not work. The dependency with this version can not be resolved. I am not sure if the url that is listed with the -f parameter in the pip3 command is even a valid source for pipenv.
I could install both libraries by just passing the command through to pip like this:
pipenv run pip install torch==1.3.1+cu92 torchvision==0.4.2+cu92 -f https://download.pytorch.org/whl/torch_stable.html
but I am not really satisfied with that solution since the dependencies are not in the Pipfile and I have to manually document the usage of this command.
Solution 1:[1]
Solved: This is how to install Torch CORRECTLY in Pipenv. Most people do this incorrectly even in various "solutions" I've seen from other people... I've researched to the bottom of this problem and found out the real, intended solution that everyone should use.
This technique is the correct one and it's documented here in the pipenv repository:
https://github.com/pypa/pipenv/issues/4961#issuecomment-1045679643
Solution 2:[2]
I've just run into this issue right now. Take whichever URL the Torch website tells you to use and do this:
pipenv install torch --index https://download.pytorch.org/whl/cu113
Of course, replace https://download.pytorch.org/whl/cu113 with the URL indicated for you by Torch. This updates the Pipfile correctly and worked in my system. Installed pytorch and enabled correct CUDA support.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mitch McMabers |
| Solution 2 | Alister Machado |
