28

I'm trying to install Pytorch with Windows and I'm using the commands of the official site https://pytorch.org/get-started/locally/

pip3 install torch==1.2.0 torchvision==0.4.0 -f https://download.pytorch.org/whl/torch_stable.html

This is the command if I choose Windows, Cuda 10.0, and Python 3.7 But if I run this I get the error message:

ERROR: Could not find a version that satisfies the requirement torch==1.2.0 (from versions: 0.1.2, 0.1.2.post1, 0.1.2.post2)
ERROR: No matching distribution found for torch==1.2.0

So why does this happen? My pip is version 19.2 and I am in a newly installed python 3.7 environment

relot
  • 651
  • 1
  • 6
  • 18
  • I am new in python and was struggling with it. I found Anaconda very useful. Just installed it and then install any library that I want from Anaconda navigator. It is available for all OS.
    https://docs.anaconda.com/anaconda/install/windows/
    –  Aug 15 '19 at 10:25

12 Answers12

28

I tried multiple solutions and it wasn't working on Windows 10 until I tried this:

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

If you want your GPU enabled then remove the "+CPU":

pip install torch==1.5.0 -f https://download.pytorch.org/whl/torch_stable.html
dippas
  • 58,591
  • 15
  • 114
  • 126
Raj Desai
  • 281
  • 3
  • 2
  • 4
    Perfect this solved the install issue for me in Python 3.8 – Jortega Jul 27 '20 at 23:50
  • 10
    It does not work for me I get ```ERROR: Could not find a version that satisfies the requirement torch==1.5.0+cpu (from versions: 0.1.2, 0.1.2.post1, 0.1.2.post2) ERROR: No matching distribution found for torch==1.5.0+cpu``` – Quinten C Nov 22 '20 at 16:26
  • @QuintenCabo did you ever solve it? I also couldnt get this to work... thanks! – yishairasowsky Sep 19 '21 at 19:01
  • @yishairasowsky It seemed to be the version of python 32 bit instead of 64 bit. But trying to install it with Conda instead will probably also work better. – Quinten C Sep 21 '21 at 21:37
  • @QuintenCabo I have 64, and I have tried miniconda. still fails... – yishairasowsky Sep 23 '21 at 06:27
  • @yishairasowsky the python version itself 3.6, 3.7, 3.8 or 3.9 can also matter. Maybe try full conda? I found that with python 3.9 it actually only has really old versions available. But that was a couple months ago. Good luck! Maybe try a different os as well perhaps. Again good luck. These things really suck if they drag out. – Quinten C Sep 25 '21 at 10:39
23

The most likely reason for Your issue is a 32-bit installation of python, while the torch libraries rely on having a 64-bit version. I had exactly the same issue.

Just start python from command line and observe

C:\Users\marci>python
Python 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] on win32

My installation now shows 64 bits. If Yours shows 32, then install 64-bit python. I used this link: Official python 64-bit Windows installer

8

I had the same issue, and what I noticed is that I was using Python 3.8.1 and the latest PyTorch was for Python 3.7.

I uninstalled Python 3.8.1 and installed 3.7.6 and voila, it worked!

Not sure if this is your case, but it helped me.

AroMorin
  • 81
  • 1
  • 4
7

So you have Cuda 10 installed? If you do, try this:

pip3 install https://download.pytorch.org/whl/cu100/torch-1.2.0-cp37-cp37m-win_amd64.whl

followed by:

pip3 install torchvision

To check if it was installed properly, type this into your command line:

python

followed by:

from __future__ import print_function
import torch
x = torch.rand(5, 3)
print(x)

If you get this output:

tensor([[0.3380, 0.3845, 0.3217],
        [0.8337, 0.9050, 0.2650],
        [0.2979, 0.7141, 0.9069],
        [0.1449, 0.1132, 0.1375],
        [0.4675, 0.3947, 0.1426]])

PyTorch was installed correctly!

DjoleRkc
  • 135
  • 7
  • 1
    pytorch binaries (e.g. wheel, conda) come prepackaged with cuda so you shouldn't even need cuda installed on the system unless you build from source. – jodag Aug 14 '19 at 20:25
  • 1
    This answer is incorrect. The definitive way to determine if cuda is working is torch.cuda.is_available(). If it does not return True your code cannot use the GPU, but the above will look exactly the same. – theoden Dec 19 '19 at 17:32
4

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

Please use this, worked out for me.

Ophir Carmi
  • 2,701
  • 1
  • 23
  • 42
1

Try installing via .whl file from Christoph Gohlke's repo at this link: https://www.lfd.uci.edu/~gohlke/pythonlibs/

Make sure you get the right one for your python version (cp37 at the bottom).

Navigate to the file or save it to your working directory, then use

pip3 install path-to-file.whl

Link to .whl file on page

Kartograaf
  • 143
  • 6
  • This doesn't contain torch 1.2 and also not Cuda 10.0 – relot Aug 14 '19 at 17:05
  • Do you need that version of pytorch? (1.2) Might be easier to install an earlier version that has binaries built for windows. Unfortunately, this happens pretty frequently when using python via windows. Another option is using anaconda. – Kartograaf Aug 14 '19 at 17:17
1

Go here https://pytorch.org/get-started/previous-versions/ and find the appropriate command for the version you want.

But first it is best to create an virtual environment with the right version of python

conda create -n you_env_name python=?.?.?

Then activate the environment

conda activate your_env_name
Anthony
  • 575
  • 6
  • 8
1

it's because your python version is 32bit while you're trying to download a 64bit version of Pytorch, navigate to pytorch_whl_page and choose an appreciate version of Pytorch or reinstall python from the official Python page to a 64bit version

Ali.M.Kamel
  • 223
  • 3
  • 14
0

try the following in your IDE command prompt then restart the IDE:

conda install pytorch -c pytorch
R2D2
  • 75
  • 1
  • 9
0

You will find the correct code to run on the PyTorch website.

There, you can choose your OS, platform, pip, conda and other customisation. For example, the code to install the PyTorch package on Windows using pip and the CUDA 10.2 platform is (without the quotes:

"pip3 install torch==1.9.0+cu102 torchvision==0.10.0+cu102 torchaudio===0.9.0 -f https://download.pytorch.org/whl/torch_stable.html"

Amaks
  • 95
  • 2
  • 6
0

Just downgrade your python version. I was using Python 3.10 then I uninstalled that and reinstalled python 3.7. It started working for me

M S M
  • 11
  • 1
-3

PyTorch is now torch.

import torch
print(help("torch"))
R2D2
  • 75
  • 1
  • 9