写在前面
自己的测试环境:
Ubuntu20.04
一、问题描述
运行python 程序时出现如下报错
ModuleNotFoundError: No module named 'torchsparse'
二、解决方法
出现上述问题的原因是缺少 torchsparse
导致的。因此需要安装 torchsparse
。
2.1 方法一:参考官方github链接
- 确保至少安装了 PyTorch 1.9.0:
python -c "import torch; print(torch.__version__)"
>>> 1.10.0
- 如果您想将 TorchSparse 与 GPU 一起使用,请确保 PyTorch 已安装 CUDA:
python -c "import torch; print(torch.version.cuda)"
>>> 11.3
- 然后,通过运行安装脚本即可找到并安装正确的 TorchSparse wheel:
python -c "$(curl -fsSL https://raw.githubusercontent.com/mit-han-lab/torchsparse/master/install.py)"
2.2 方法二:使用指令安装
使用如下指令进行安装:
注意:版本号 v2.1.0
可以修改, 因为官方github中README.md/Installation
中推荐安装 v2.1.0
, 并且我自己的电脑 torch.__version__==2.1.2
, torch.version.cuda==11.8
(版本都比较高,并且高于官方github中的演示版本),所以我这里也安装 v2.1.0
。
sudo apt-get install libsparsehash-dev
pip install --upgrade git+https://github.com/mit-han-lab/torchsparse.git@v2.1.0
参考链接
[1] mit-han-lab. torchsparse [EB/OL]. https://github.com/mit-han-lab/torchsparse, 2024-11-13/2024-12-01.
[2] 我是好人BING. torchsparse安装 [EB/OL]. https://blog.youkuaiyun.com/AI_BING_/article/details/124991818, 2023-12-27/2024-12-01.