如何使用 PyCharm 和 Pytorch 获取快速文档

Rea*_*lar 9 python machine-learning pycharm pytorch

我在 Windows 10 上运行PyCharm,并按照入门指南安装了PyTorch。我使用Chocolatey和 Anaconda 来设置一切。

我可以从 PyCharm IDE 内部运行 PyTorch 教程,没有任何问题。所以我觉得我有一个适当的设置,但没有任何 PyTorch API 的智能感知文档。

例如;

import torch

x = torch.randn(128, 20)
Run Code Online (Sandbox Code Playgroud)

如果我将鼠标悬停randn并按下CTRL+Q,那么 PyCharm 会向我显示一个没有任何文档的函数定义的弹出窗口。

我期待从 API 文档中看到该函数的 Python 注释:

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

我是 Pytorch 和 Python 的新手,但这是我经常可以从 IDE 内部使用许多其他语言和库访问的内容。所以我觉得这应该可以开始工作,但我似乎找不到任何关于如何解决这个问题的说明。

Rea*_*lar 7

我能够通过执行以下操作来使其工作:

PyStorm 2019.3

打开外部文档的设置:

文件/设置/工具/外部文档

添加以下 URL 模式:

Module Name: torch.nn.functional
        URL: https://pytorch.org/docs/stable/nn.functional.html#{element.qname}
Run Code Online (Sandbox Code Playgroud)
Module Name: torch
        URL: https://pytorch.org/docs/stable/{module.basename}.html#{element.qname}
Run Code Online (Sandbox Code Playgroud)

似乎适用于大多数 API,但您必须触发快速文档工具窗口。如果你有CTRL+CLICK什么,这不会显示文档。