问题
I am trying to install pytorch on windows and there is one which is available for it but shows an error.
conda install -c peterjc123 pytorch=0.1.12
回答1:
Warning: Unless you have a very specific reason not to, just follow the official installation instructions from https://pytorch.org. They are far more likely to be accurate and up-to-date.
Here is how to install the PyTorch package from the official channel, on Windows using Anaconda, as of the time of writing this comment (31/03/2020):
PyTorch without CUDA:
conda install pytorch torchvision cpuonly -c pytorch
PyTorch with CUDA 10.1:
conda install pytorch torchvision cudatoolkit=10.1 -c pytorch
回答2:
go to the official website: http://pytorch.org/
- Select Windows as your operating system
- Select your Package Manager such as pip or conda
- Select you python version
- Select CUDA or choose none You will get the command that will install pytorch on your system based on your selection.
For example, if you choose Windows, pip, python 3.6 and none in the listed steps, you will get the following commands:
pip3 install http://download.pytorch.org/whl/cpu/torch-0.4.0-cp36-cp36m-win_amd64.whl
pip3 install torchvision
回答3:
Actual answer:
Best way is to check on the official website for up-to-date options. Here are the ones working as of 2020-03:
# for windows 10, CUDA 10.1
conda install pytorch torchvision cudatoolkit=10.1 -c pytorch
#for windows 10, CUDA 9
conda install pytorch torchvision cudatoolkit=9.2 -c pytorch -c defaults -c numba/label/dev
Previous answer(out-of-date)
It seems that the author (peterjc123) released 2 days ago conda packages to install PyTorch 0.3.0 on windows. Here is a copy:
# for Windows 10 and Windows Server 2016, CUDA 8
conda install -c peterjc123 pytorch cuda80
# for Windows 10 and Windows Server 2016, CUDA 9
conda install -c peterjc123 pytorch cuda90
# for Windows 7/8/8.1 and Windows Server 2008/2012, CUDA 8
conda install -c peterjc123 pytorch_legacy cuda80
source: https://github.com/pytorch/pytorch/issues/494#issuecomment-350527200
回答4:
If you are trying to install on windows 10 and you are not having the anaconda installation than the best options are below:
Python 2.7
pip install https://download.pytorch.org/whl/cpu/torch-1.0.1-cp27-cp27mu-linux_x86_64.whl
pip install torchvision
If the above command does not work, then you have python 2.7 UCS2, use this command
pip install https://download.pytorch.org/whl/cpu/torch-1.0.1-cp27-cp27m-linux_x86_64.whl
Python 3.5
pip3 install https://download.pytorch.org/whl/cpu/torch-1.0.1-cp35-cp35m-win_amd64.whl
pip3 install torchvision
Python 3.6
pip3 install https://download.pytorch.org/whl/cpu/torch-1.0.1-cp36-cp36m-win_amd64.whl
pip3 install torchvision
Python 3.7
pip3 install https://download.pytorch.org/whl/cpu/torch-1.0.1-cp37-cp37m-win_amd64.whl
pip3 install torchvision
回答5:
Update June 2019: pytorch has a dedicated conda channel now and can be installed easily with anaconda. The command generated at pytorch will require dependencies before it can be executed successfully. For example I chose stable pytorch 1.1 build with python 3.6 and Cuda 10.0. The command generated by pytorch page was as follows:
conda install pytorch torchvision cudatoolkit=10.0 -c pytorch
But it will not work if you have created a new conda environment like me. The step by step process for setting up pytorch is as follows:
- First install the cudatoolkit as follows:
conda install -c anaconda cudatoolkit=10.0
- Then install the mkl_fft as follows:
conda install -c anaconda mkl_fft
- Assuming you will face no more dependency issues. Use the following command to setup pytorch:
conda install -c pytorch pytorch
This worked for me. But I had setup my new conda environment with scikit-learn and jupyter notebook before starting the pytorch setup. So if any dependency problem arise, it would be a good idea to install both scikit-learn and jupyter notebook as well.
回答6:
The trick is to go to the PyTorch website and select the things you need:
回答7:
Try running:
conda install -c pytorch pytorch
The command will update/install: conda, cudatoolkit, pytorch.
回答8:
You may want to consider using Docker for Windows. This would enable you to install pytorch as you would on Linux. Although, I believe that DfW has limited CUDA support, so you may want to explore a different option if you plan on using CUDA.
回答9:
I was getting some kind of Rollback error
on Git bash and Windows Cmd prompt so had to run Anaconda prompt as admin for:
conda install pytorch-cpu -c pytorch
and then I got another when I tried the following command on Anaconda prompt:
pip3 install torchvision
so I switched back to Windows prompt to enter it and it worked.
To test the installation, I ran this from Git Bash:
$ python reinforcement_q_learning.py
with source code that looks like (the snippet near the top anyways):
"""
import gym
import math
import random
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
from collections import namedtuple
from itertools import count
from PIL import Image
import torch
import torch.nn as nn
import torch.optim as optim
import torch.nn.functional as F
import torchvision.transforms as T
env = gym.make('CartPole-v0').unwrapped
# set up matplotlib
is_ipython = 'inline' in matplotlib.get_backend()
if is_ipython:
from IPython import display
plt.ion()
# if gpu is to be used
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
######################################################################
# Replay Memory
# -------------
#
# We'll be using experience replay memory for training our DQN. It stores
# the transitions that the agent observes, allowing us to reuse this data
# later. By sampling from it randomly, the transitions that build up a
# batch are decorrelated. It has been shown that this greatly stabilizes
# and improves the DQN training procedure.
#
# For this, we're going to need two classses:
#
# - ``Transition`` - a named tuple representing a single transition in
# our environment. It maps essentially maps (state, action) pairs
# to their (next_state, reward) result, with the state being the
# screen difference image as described later on.
# - ``ReplayMemory`` - a cyclic buffer of bounded size that holds the
# transitions observed recently. It also implements a ``.sample()``
# method for selecting a random batch of transitions for training.
#
Transition = namedtuple('Transition',
('state', 'action', 'next_state', 'reward'))
class ReplayMemory(object):
def __init__(self, capacity):
self.capacity = capacity
self.memory = []
self.position = 0
def push(self, *args):
"""Saves a transition."""
if len(self.memory) < self.capacity:
self.memory.append(None)
self.memory[self.position] = Transition(*args)
self.position = (self.position + 1) % self.capacity
def sample(self, batch_size):
return random.sample(self.memory, batch_size)
def __len__(self):
return len(self.memory)
############continues to line 507...
回答10:
Try this
- cd C:\Program files\Anaconda3\condabin
- conda install pytorch-cpu torchvision-cpu -c pytorch
https://pytorch.org/get-started/locally/#anaconda
回答11:
for python 3.7 which is the latest till date
for pytorch on cpu
pip install https://download.pytorch.org/whl/cpu/torch-1.0.1-cp37-cp37m-win_amd64.whl
pip install torchvision
回答12:
If @x0s answer gives dependency issues then try updating conda before that.
conda update conda
conda install -c peterjc123 pytorch_legacy cuda80
回答13:
This Line of code did the trick for me:
conda install -c peterjc123 pytorch
Check these links out in case you have any problem installing:
Superdatascience Tutorial Explains Clearly how to do it.
Or just go to the anaconda pytorch page: https://anaconda.org/peterjc123/pytorch
It worked for me.Hope my answer was useful.
来源:https://stackoverflow.com/questions/47754749/how-to-install-pytorch-in-windows