PyTorch:错误消息“torch has no [...] member" [英] PyTorch : error message "torch has no [...] member"

查看:37
本文介绍了PyTorch:错误消息“torch has no [...] member"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

晚上好,我刚刚安装了 PyTorch 0.4.0,我正在尝试执行第一个教程什么是 PyTorch?"我编写了一个 Tutorial.py 文件,我尝试使用 Visual Studio Code 执行该文件

Good evening, I have just installed PyTorch 0.4.0 and I'm trying to carry out the first tutorial "What is PyTorch?" I have written a Tutorial.py file which I try to execute with Visual Studio Code

代码如下:

from __future__ import print_function
import torch

print (torch.__version__)

x = x = torch.rand(5, 3)
print(x)

不幸的是,当我尝试调试它时,我收到一条错误消息:torch 没有 rand 成员"

Unfortunately, when I try to debug it, i have an error message : "torch has no rand member"

我可以尝试的任何 Torch 成员函数都是如此

This is true with any member function of torch I may try

有人可以帮我吗?

推荐答案

以防您的问题没有解决方案或其他人遇到.

该错误是由于 Pylint(Python 静态代码分析工具)未将 rand 识别为成员函数而引发的.您可以将 Pylint 配置为忽略这个问题,或者您可以通过在 .pylintrc 中添加以下内容来将 Torch 列入白名单(更好的解决方案)以消除 lint 错误文件.

The error is raised because of Pylint (Python static code analysis tool) not recognizing rand as the member function. You can either configure Pylint to ignore this problem or you can whitelist torch (better solution) to remove lint errors by adding following to your .pylintrc file.

[TYPECHECK]

# List of members which are set dynamically and missed by Pylint inference
# system, and so shouldn't trigger E1101 when accessed.
generated-members=numpy.*, torch.*

在 Visual Studio Code 中,您还可以将以下内容添加到用户设置中:

In Visual Studio Code, you could also add the following to the user settings:

"python.linting.pylintArgs": [
"--generated-members=numpy.* ,torch.*"
]

在 PyTorch GitHub 页面上此处讨论了该问题.

The issue is discussed here on PyTorch GitHub page.

这篇关于PyTorch:错误消息“torch has no [...] member"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆