安装pytorch-vision时遇到的g++错误

我之前在cpu电脑上安装过pytorch和pytorch-vision,在安装了pytorch以后,python中import torch会缺少文件,必须安装pytorch-vision才能正常import。
之后我又安装了GPU电脑上的pytorch,情况一样,安装好pytorch之后,python中import torch还是缺少文件,之后系统会报错:

subprocess.CalledProcessError: Command '['ninja', '-v']' returned non-zero exit status 1.

到下面的报错信息中,找extension.py文件,我的是anaconda3/lib/python3.8/site-packages/torch/utils/cpp_extension.py,打开这个文件,将

command = ['ninja', '-v']

改成

command = ['ninja', '--version']

这个问题解决后,之后还有报错:

g++: error: /home/danalelixin/Desktop/vision/build/temp.linux-x86_64-3.8/home/danalelixin/Desktop/vision/torchvision/csrc/vision.o: No such file or directory
g++: error: /home/danalelixin/Desktop/vision/build/temp.linux-x86_64-3.8/home/danalelixin/Desktop/vision/torchvision/csrc/cpu/PSROIAlign_cpu.o: No such file or directory
g++: error: /home/danalelixin/Desktop/vision/build/temp.linux-x86_64-3.8/home/danalelixin/Desktop/vision/torchvision/csrc/cpu/DeformConv_cpu.o: No such file or directory
g++: error: /home/danalelixin/Desktop/vision/build/temp.linux-x86_64-3.8/home/danalelixin/Desktop/vision/torchvision/csrc/cpu/ROIPool_cpu.o: No such file or directory
g++: error: /home/danalelixin/Desktop/vision/build/temp.linux-x86_64-3.8/home/danalelixin/Desktop/vision/torchvision/csrc/cpu/ROIAlign_cpu.o: No such file or directory
g++: error: /home/danalelixin/Desktop/vision/build/temp.linux-x86_64-3.8/home/danalelixin/Desktop/vision/torchvision/csrc/cpu/nms_cpu.o: No such file or directory
g++: error: /home/danalelixin/Desktop/vision/build/temp.linux-x86_64-3.8/home/danalelixin/Desktop/vision/torchvision/csrc/cpu/PSROIPool_cpu.o: No such file or directory
g++: error: /home/danalelixin/Desktop/vision/build/temp.linux-x86_64-3.8/home/danalelixin/Desktop/vision/torchvision/csrc/cuda/ROIAlign_cuda.o: No such file or directory
g++: error: /home/danalelixin/Desktop/vision/build/temp.linux-x86_64-3.8/home/danalelixin/Desktop/vision/torchvision/csrc/cuda/PSROIAlign_cuda.o: No such file or directory
g++: error: /home/danalelixin/Desktop/vision/build/temp.linux-x86_64-3.8/home/danalelixin/Desktop/vision/torchvision/csrc/cuda/PSROIPool_cuda.o: No such file or directory
g++: error: /home/danalelixin/Desktop/vision/build/temp.linux-x86_64-3.8/home/danalelixin/Desktop/vision/torchvision/csrc/cuda/nms_cuda.o: No such file or directory
g++: error: /home/danalelixin/Desktop/vision/build/temp.linux-x86_64-3.8/home/danalelixin/Desktop/vision/torchvision/csrc/cuda/DeformConv_cuda.o: No such file or directory
g++: error: /home/danalelixin/Desktop/vision/build/temp.linux-x86_64-3.8/home/danalelixin/Desktop/vision/torchvision/csrc/cuda/ROIPool_cuda.o: No such file or directory
error: command 'g++' failed with exit status 1

这个问题我现在还没有找到解决的方式,但是现在python中import torch以后,不会报错了,最神奇的是import torchvision也不会报错,也就是说已经不影响使用了。
如果以后有需要,或者我解决了问题,我在更新,如果有大佬有解决问题的方式,敬请指教。

评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值