Reactgular
Reactgular

Reputation: 54771

How to get quick documentation working with PyCharm and Pytorch

I'm running PyCharm on Windows 10, and installed PyTorch following the getting started guide. Where I used Chocolatey and Anaconda to set up everything.

I can run the PyTorch tutorials from inside the PyCharm IDE without any problems. So I feel like I have a proper set up, but there aren't any intellisense documentations for any of the PyTorch APIs.

For example;

import torch

x = torch.randn(128, 20)

If I mouse over randn and press CTRL+Q then PyCharm shows me a popup of the function definition without any documentation.

I'm expecting to see Python comments from the API documentation for that function:

https://pytorch.org/docs/stable/torch.html?highlight=randn#torch.randn

I'm a new beginner with Pytorch and Python, but this is something that I often have access to from inside the IDE with many other languages and libraries. So I feel like this should be possible to get working, but I can't seem to find any instructions on how to fix this.

Upvotes: 9

Views: 1841

Answers (4)

Chunhui Gu
Chunhui Gu

Reputation: 39

I was about just to add a comment for Reactgular's solution but it turned out I didn't have enough "reputation" to do it.

For the torch.nn.functional module, I found it is more helpful to do this to jump directly to the detailed documentation for the function you are searching for.

torch.nn.functional
https://pytorch.org/docs/stable/generated/{element.qname}.html#{element.qname}

But of course, this is not a stable page so I guess it may not work later, so be careful about it.

Upvotes: 1

M.Q.
M.Q.

Reputation: 1

PyCharm2022.1.x still cannot display torch(1.10) documentation. @Reactgular 's answer is helpful. But the url that works for me is different.

Following the steps: file --settings--tools -- external documentation -- add

Module Name: torch URL/Path Pattern: https://pytorch.org/docs/stable/generated/{element.qname}.html#{element.qname}

Actually the above steps only let the pycharm show a link. But it is better than nothing. just click the link and a default browser will open the documentation. You can also specify a customized browser instead of the system default browser: file-- settings-- tools --web browsers and preview

torch quick doc

Upvotes: 0

theX
theX

Reputation: 1124

You probably want to get Kite. It has this feature (that I use intensively) called co-pilot where you can get python docs immediately. I don't know if it's Linux/Mac specific but works for any editor, nit just Pycharm.

It's just another solution

Upvotes: 1

Reactgular
Reactgular

Reputation: 54771

I was able to get it working by doing the following:

PyStorm 2019.3

Open the settings for external documentation:

File / Settings / Tools / External Documentation

Add the following URL patterns:

Module Name: torch.nn.functional
        URL: https://pytorch.org/docs/stable/nn.functional.html#{element.qname}
Module Name: torch
        URL: https://pytorch.org/docs/stable/{module.basename}.html#{element.qname}

Seems to work for most APIs but you have to trigger the quick documentation tool window. This won't show docs if you CTRL+CLICK something.

Upvotes: 8

Related Questions