Windows环境下安装PyTorch后无法导入的问题求助
Hey there! Let's break down why your PyTorch import isn't working and fix it step by step.
What Went Wrong
You installed a CUDA-enabled version of PyTorch 0.3.1 from the peterjc123 channel, but since you don't have an NVIDIA GPU, this package tries to load CUDA libraries that aren't present on your system. On top of that, third-party channels like peterjc123 don't always offer the same reliability as official PyTorch packages, especially for older versions.
Step 1: Uninstall the Problematic Package
First, let's remove the broken PyTorch installation completely. Open your conda terminal and run:
conda uninstall pytorch
Follow the on-screen prompts to confirm the uninstallation.
Step 2: Install the Official CPU-only PyTorch
Since you're using Python 3.6 and don't have a GPU, we'll install an official CPU-compatible version that works with your setup. Python 3.6 supports PyTorch versions up to 1.5.x, so we'll use that for compatibility.
Option A: Using Conda
This is the most reliable method for conda environments:
conda install pytorch-cpu torchvision-cpu -c pytorch
This pulls official CPU-only packages directly from PyTorch's conda channel.
Option B: Using Pip
If conda runs into compatibility issues, try pip instead:
pip install torch==1.5.0+cpu torchvision==0.6.0+cpu
If pip can't locate the package, you can download the appropriate wheel file for Python 3.6 from PyTorch's official archive and install it locally with pip install <path-to-your-downloaded-wheel-file>.
Step 3: Verify the Installation
Open a Python shell (or your IDE's terminal) and test the import:
import torch print(torch.__version__) print(torch.cuda.is_available()) # This should return False, which is normal for a CPU-only setup
If you don't get any error messages, your PyTorch installation is working correctly!
内容的提问来源于stack exchange,提问作者Eypros

