解决PyTorch错误:AttributeError: module ‘torch’ has no attribute ‘_six’

1. 问题描述:我是在VScode中使用jupyter拓展,远程连接服务器。

2. torch版本:2.0

3. pytorch版本: 1.9.1

4. 问题原因:torch 2.0版本以后中没有 ‘_six.py’ 文件

5. 如何查看torch中的py文件?
我是用的anaconda,torch中的py文件位置为:

/envs/环境名/lib/python版本号(比如:python3.8)/site-packages/torch


6. 解决办法
(1)我第一开始试着把torch1.9中的’_six.py’文件复制到torch2.0中,发现还是不行(不知道为啥,有大佬能解释一下吗?)
然后我又重新装了torch1.9.1,问题解决了!
步骤如下:

pip uninstall torch
pip install torch==1.9.1

Tips: 如果在步骤5中发现有’_six.py’文件,可以点击重启jupyter kernel即可解决。

物联沃分享整理
物联沃-IOTWORD物联网 » 解决PyTorch错误:AttributeError: module ‘torch’ has no attribute ‘_six’

发表评论