如何在当前环境中卸载gpu版本的pytorch并下载cpu版本的pytorch
时间: 2024-10-18 20:15:50 浏览: 80
在当前环境中卸载GPU版本的PyTorch并安装CPU版本,你可以按照以下步骤操作:
1. **确认已安装的PyTorch版本**:
打开命令行(Windows上是CMD或PowerShell,Linux/Mac上是终端),输入 `pip list | grep torch` 或者 `conda list | grep pytorch` 来查看已安装的PyTorch版本。
2. **卸载GPU版本** (使用pip):
如果你是通过pip安装的,可以运行:
```
pip uninstall torch torchvision torchaudio -y
```
或者如果你使用的是Conda,可以尝试:
```
conda remove -c pytorch pytorch torchvision torchaudio -y
```
`-y` 参数表示默认确认删除,无需手动输入 `yes`。
3. **检查是否移除成功**:
再次运行 `pip list | grep torch` 或 `conda list | grep pytorch` 确认GPU版本是否已经卸载。
4. **安装CPU版本**:
对于pip安装:
```
pip install torch torchvision torchaudio -f https://download.pytorch.org/whl/cpu/torch_stable.html
```
对于Conda,你可能需要创建一个新的环境再安装:
```
conda create -n my_cpu_env python=3.7
conda activate my_cpu_env
conda install pytorch torchvision torchaudio -c pytorch
```
5. **验证安装**:
安装完毕后,可以导入PyTorch看看是否为CPU版本,如:
```python
import torch
print(torch.cuda.is_available()) # 这将返回False,说明现在使用的是CPU。
```
阅读全文
相关推荐


















