How did you get “there are no graph nodes that require computing gradients”?
But anyways, I tweaked the code a little and you can call backwards on it:
import torch
from torch.autograd import Variable

def distance(input, means):
     df = 1
     dist = Variable(torch.zeros(means.size(0), input.size(0)))
     for i in range(means.size()[0]):
          dist[i] = torch.pow(1 + torch.sum(torch.pow(input - means[i], 2), 1) / df, -(1 + df)/2)
     return dist.t()

x = Variable(torch.randn(2, 2), requires_grad=True)
means = Variable(torch.randn(2), requires_grad=False)
out = distance(input, means).sum()
out.backward()
x.grad  # prints something

You have to wrap your tensors in Variables so that autograd can keep track of them to compute backwards.