我之前在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也不会报错,也就是说已经不影响使用了。
如果以后有需要,或者我解决了问题,我在更新,如果有大佬有解决问题的方式,敬请指教。