module ‘torch‘ has no attribute ‘__version__‘,No module named ‘torch.nn‘; ‘torch‘ is not a package解决

报错:

写了个网络,运行时报错:
No module named 'torch.nn'; 'torch' is not a package

运行

print(torch.__version__)

报错

module 'torch' has no attribute '__version__'

解决

检查pytorch版本,以及是否安装等问题均未发现错误,最后发现是文件命名问题,我把文件命名为 torch.py,改个名就行了

你可能感兴趣的:(ubuntu,pytorch,ubuntu,pytorch)