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
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
pip install torch==1.5.0+cpu torchvision==0.6.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
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.
I was using the official website(https://pytorch.org/get-started/locally/) where the following command is mentioned for Windows 10 & Conda environment:
conda install pytorch torchvision cudatoolkit=10.2 -c pytorch
I ran this command in Anaconda command prompt but I was getting stuck as there were following errors
ERROR conda.core.link:_execute(502): An error occurred while uninstalling package 'defaults::pycurl-7.43.0.1-py36h74b6da3_0'. WindowsError(5, 'Access is denied')
To rectify this I opened the Anaconda command prompt as administrator and then ran the same command again. It solved the access issue and allowed the package to get installed.
So you just have to use following two steps:
Step 1: Open Anaconda prompt as administrator
Step 2: run following command
conda install pytorch torchvision cudatoolkit=10.2 -c pytorch
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...
If @x0s answer gives dependency issues then try updating conda before that.
conda update conda
conda install -c peterjc123 pytorch_legacy cuda80