VSCode 中 torch has no xxx member
VSCode中pytorch出现’torch’ has no member 'xxx’的错误
win10解决方案:
Win10 中使用Anaconda安装完pytorch后
 在VSCode中输入代码时发现,对于很多需要用到的torch里的函数,VSCode均会报错。
‘torch’ has no member ‘xxx’
经过搜索资料,找到了解决办法。
在VSCode setting中搜索python.linting.pylintPath
 并且修改值为(你的Anaconda安装路径)\pkgs\pylint-1.8.4-py36_0\Scripts\pylint,修改完后就不会再报错了。
 如下图:
 
Ubuntu解决方案:
同理win10,在reference中的setting中搜索python.linting.pylintPath
 添加项为pylint的路径,如/home/xxx/.local/lib/python3.7/site-packages/pylint
 (.local为隐藏目录,可以在主目录下按 ctrl+H显示隐藏目录)
对于anaconda的环境,则进入anaconda的安装目录,找到envs,找到需要添加的环境,例如我这里是在用cs231n时报错,那就进入cs231n的环境,进入/lib/python3.7/site-packages
/home/xxx/anaconda3/envs/cs231n/lib/python3.7/site-packages
 添加这个选项后,电脑异常卡顿,打开VSCode很快就占用内存过半,交换空间最后也满了,直接电脑卡死。但是去掉这个选项后pytorch的疯狂报错。
解决方案如下:
在编辑器中找到文件->首选项->设置
 
 然后搜索search.follow,将“控制是否在搜索中跟踪符号链接”的√去掉, 然后搜索exclude,在Files:exclude下面有一个添加模式,输入**/node_modules,设置忽略node_modules这个文件夹。
 设置后如下图所示:
 
 需要及其注意的一点是千万不能把
 python.linting.pylintPath和python.linting.pylintArgs的参数填错,否则VSCode会变得异常卡顿,
同时,如果出现VSCode打开py文件报Unable to import xxx(pytest) pylint(import-error),但是你已经安装了pytest,那么就一定要检查python.linting.pylintPath和python.linting.pylintArgs的参数。
 然后在VSCode中打开文件->首选项->设置,搜索Python>Linting>Pylint Args,点击添加项。添加以下两项:
--errors-only
--disable=E0401
 
如下图:
 
                    
                
                
            
        
浙公网安备 33010602011771号