python应用运行报错,部分错误信息如下:
Traceback (most recent call last):
packages\torch\nn\modules\module.py”, line 780, in _apply module._apply(fn) File “\lib\site-packages\torch\nn\modules\module.py”, line 780, in _apply module._apply(fn) File “lib\site-packages\torch\nn\modules\module.py”, line 805, in _apply param_applied = fn(param) File “lib\site-packages\torch\nn\modules\module.py”, line 1160, in convert return t.to( File “lib\site-packages\torch\cuda__init_.py”, line 305, in _lazy_init
raise AssertionError(“Torch not compiled with CUDA enabled”)
AssertionError: Torch not compiled with CUDA enabled
输出信息提示Torch 未启用 CUDA 进行编译,也就是Python环境安装的torch不是cuda版本,先运行pip uninstall torch 卸载,如果有torchvision torchaudio也一同卸载,然后运行下面命令安装cuda版本torch
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu124
安装完成后重新运行Python应用即可