晚上好,我刚刚安装了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)
Run Code Online (Sandbox Code Playgroud)
不幸的是,当我尝试调试它时,出现错误消息:“ torch没有rand成员”
我尝试使用的任何手电筒功能都是如此
有人可以帮我吗?
kHa*_*hit 18
如果您没有解决问题的方法,或者其他人遇到了问题。
由于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.*
Run Code Online (Sandbox Code Playgroud)
在Visual Studio Code中,还可以将以下内容添加到用户设置:
"python.linting.pylintArgs": [
"--generated-members=numpy.* ,torch.*"
]
Run Code Online (Sandbox Code Playgroud)
这个问题进行了讨论这里 PyTorch GitHub的页面上。
pylint 的快速解决方案没有成员问题但代码仍然有效 vscode
Press: CTRL + Shift + P
Click on "Preferences: Open Settings (JSON)"
Add this line into JSON : "python.linting.pylintArgs": ["--generate-members"]
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6088 次 |
| 最近记录: |