No module named 'torch.autograd'
Working with torch package:

import torch

from torch.autograd import Variable

x_data = [1.0,2.0,3.0]

y_data = [2.0,4.0,6.0]

w = Variable(torch.Tensor([1.0]), requires_grad = True)

def forward(x):

return x*w

def loss(x,y):

y_pred = forward(x)

return (y_pred-y)*(y_pred-y)

print("my prediction before training",4,forward(4))

for epoch in range(10):

for x_val, y_val in zip(x_data,y_data):

l= loss(x_val, y_val)

l.backward()

print("\tgrad: ", x_val, y_val, w.grad.data[0])

w.data=w.data-0.01*w.grad.data

w.grad.data.zero_()

print("progress:", epoch, l.data[0] )

print("my new prediction after training ", forward(4))


Got error:

runfile('C:/gdrive/python/temp2.py', wdir='C:/gdrive/python')

Traceback (most recent call last):

File "C:\gdrive\python\temp2.py", line 11, in &lt;module&gt;

from torch.autograd import Variable

ModuleNotFoundError: No module named 'torch.autograd'


Command conda list pytorch brings:

# packages in environment at C:\Users\g\.conda\envs\test:

#

# Name Version Build Channel

(test) PS C:\gdrive\python&gt;


How to fix this problem?

It seems to me that you have installed pytorch using conda.
Might be you have torch named folder in your current directory. 
Try changing the directory, or try installing pytorch using pip.
This https://github.com/pytorch/pytorch/issues/1851 might help you to solve your problem.
