PyTorch:错误消息"火炬没有[...]成员"

时间:2018-05-13 19:36:27

标签: torch pytorch

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

执行

以下是代码:

from __future__ import print_function
import torch

print (torch.__version__)

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

不幸的是,当我尝试调试它时,我有一条错误消息: "火炬没有兰特成员"

对于火炬的任何成员函数我都可以尝试

有人可以帮帮我吗?

4 个答案:

答案 0 :(得分:9)

如果您没有解决问题的方法,或者其他人遇到了问题。

由于Pylint( Python静态代码分析工具)未将rand识别为成员函数,因此引发了错误。您可以将Pylint配置为忽略此问题,也可以将割炬列入白名单(更好的解决方案)以通过在.pylintrc文件中添加以下内容来消除棉绒错误。

[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中,您还可以将以下内容添加到用户设置:

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

在PyTorch GitHub页面上here讨论了该问题。

答案 1 :(得分:5)

来自pylint no member issue but code still works vscode的快速解决方案

Press: CTRL + Shift + P

Click on "Preferences: Open Settings (JSON)"

Add this line into JSON : "python.linting.pylintArgs": ["--generate-members"]

答案 2 :(得分:1)

如果仍然有人遇到问题,那么这是对我有用的解决方案。 转到vs代码设置,import { Component } from '@angular/core'; @Component({ selector: 'my-app', templateUrl: './app.component.html', styleUrls: [ './app.component.css' ] }) export class AppComponent { files_dropped: File[] = []; dimensions: any = []; dataArr: any = []; onSelect(event) { this.dimensions = []; this.files_dropped.push(...event.addedFiles); // use let, not var so we can access `i` inside the event listenr for (let i = 0; i < this.files_dropped.length; i++) { const reader = new FileReader(); // Note the arrow function here, this allows proper scoping so you can still use `this` instead of setting other variables to this. reader.addEventListener("load", () => { const img = document.createElement("img") as HTMLImageElement; img.onload = () => { this.dimensions.push({"width": img.naturalWidth, "height": img.naturalHeight}); console.log(this.dimensions[0].width); // this whole event listner is async, so this data array needs to be done inside here or else it runs before the event listener and will be undefined. this.dataArr = [ { "name": this.files_dropped[i].name, "size": this.files_dropped[i].size, "type": this.files_dropped[i].type, "modified": this.files_dropped[i].lastModified, "width": this.dimensions[0].width } ]; console.log(this.dataArr); } img.src = reader.result as string; }, false); reader.readAsDataURL(this.files_dropped[i]); } } onRemove(event) { console.log(event); this.files_dropped.splice(this.files_dropped.indexOf(event), 1); } } 或使用快捷键file>preferences>settings并搜索ctrl+,。 修改pylint路径,转到您的python.linting.pylintPath,然后将路径复制粘贴到设置中,并在路径末尾添加anaconda installation directory>pkgs>pylint>scripts,类似这样的pylint

答案 3 :(得分:-1)

在 VS Code 中,可以通过以下方式选择 flake8

<块引用>

Ctrl + Shift + P -> 选择 linter -> flake8

Source