在学习李沐大神的深度学习时,windows环境下的配置

小白记录:在虚拟环境下运行jupyter notebook 遇到以下问题UserWarning: Failed to load image Python extension: [WinError 127]。此问题属于解决pytorch与torchvision版本不兼容问题(解决UserWarning: Failed to load image Python extension: [WinError 127]

(mnist) C:\Users\jmzhu>python
Python 3.9.21 (main, Dec 11 2024, 16:35:24) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> print(torch.__version__)
2.7.0+cpu

查看对应的torchvision 版本为0.18.0版本,可是直接按照

(mnist) C:\Users\jmzhu>conda install torchvision==0.18.0
Channels:
 - defaults
Platform: win-64
Collecting package metadata (repodata.json): done
Solving environment: failed

PackagesNotFoundError: The following packages are not available from current channels:

  - torchvision==0.18.0

Current channels:

  - defaults

To search for alternate channels that may provide the conda package you're
looking for, navigate to

    https://anaconda.org

and use the search bar at the top of the page.
出现错误,然后先卸载

(mnist) C:\Users\jmzhu>pip uninstall torchvision
Found existing installation: torchvision 0.13.1+cpu
Uninstalling torchvision-0.13.1+cpu:
  Would remove:
    c:\users\jmzhu\anaconda3\envs\mnist\lib\site-packages\torchvision-0.13.1+cpu.dist-info\*
    c:\users\jmzhu\anaconda3\envs\mnist\lib\site-packages\torchvision\*
Proceed (Y/n)? y
  Successfully uninstalled torchvision-0.13.1+cpu

(mnist) C:\Users\jmzhu>pip install torchvision==0.18.0+cpu
ERROR: Ignored the following yanked versions: 0.1.6, 0.1.7, 0.1.8, 0.1.9, 0.2.0, 0.2.1, 0.2.2, 0.2.2.post2, 0.2.2.post3, 0.11.0, 0.15.0
ERROR: Could not find a version that satisfies the requirement torchvision==0.18.0+cpu (from versions: 0.9.0, 0.9.1, 0.10.0, 0.10.1, 0.11.1, 0.11.2, 0.11.3, 0.12.0, 0.13.0, 0.13.1, 0.14.0, 0.14.1, 0.15.1, 0.15.2, 0.16.0, 0.16.1, 0.16.2, 0.17.0, 0.17.1, 0.17.2, 0.18.0, 0.18.1, 0.19.0, 0.19.1, 0.20.0, 0.20.1, 0.21.0, 0.22.0)
ERROR: No matching distribution found for torchvision==0.18.0+cpu

然后安装相应版本,成功了 (mnist) C:\Users\jmzhu>pip install torchvision==0.18.0

Collecting torchvision==0.18.0
  Downloading torchvision-0.18.0-cp39-cp39-win_amd64.whl.metadata (6.6 kB)
Requirement already satisfied: numpy in c:\users\jmzhu\anaconda3\envs\mnist\lib\site-packages (from torchvision==0.18.0) (1.23.5)
Collecting torch==2.3.0 (from torchvision==0.18.0)
  Downloading torch-2.3.0-cp39-cp39-win_amd64.whl.metadata (26 kB)
Requirement already satisfied: pillow!=8.3.*,>=5.3.0 in c:\users\jmzhu\anaconda3\envs\mnist\lib\site-packages (from torchvision==0.18.0) (11.2.1)
Requirement already satisfied: filelock in c:\users\jmzhu\anaconda3\envs\mnist\lib\site-packages (from torch==2.3.0->torchvision==0.18.0) (3.18.0)
Requirement already satisfied: typing-extensions>=4.8.0 in c:\users\jmzhu\anaconda3\envs\mnist\lib\site-packages (from torch==2.3.0->torchvision==0.18.0) (4.13.2)
Requirement already satisfied: sympy in c:\users\jmzhu\anaconda3\envs\mnist\lib\site-packages (from torch==2.3.0->torchvision==0.18.0) (1.14.0)
Requirement already satisfied: networkx in c:\users\jmzhu\anaconda3\envs\mnist\lib\site-packages (from torch==2.3.0->torchvision==0.18.0) (3.2.1)
Requirement already satisfied: jinja2 in c:\users\jmzhu\anaconda3\envs\mnist\lib\site-packages (from torch==2.3.0->torchvision==0.18.0) (3.1.6)
Requirement already satisfied: fsspec in c:\users\jmzhu\anaconda3\envs\mnist\lib\site-packages (from torch==2.3.0->torchvision==0.18.0) (2025.3.2)
Collecting mkl<=2021.4.0,>=2021.1.1 (from torch==2.3.0->torchvision==0.18.0)
  Downloading mkl-2021.4.0-py2.py3-none-win_amd64.whl.metadata (1.4 kB)
Collecting intel-openmp==2021.* (from mkl<=2021.4.0,>=2021.1.1->torch==2.3.0->torchvision==0.18.0)
  Downloading intel_openmp-2021.4.0-py2.py3-none-win_amd64.whl.metadata (1.2 kB)
Collecting tbb==2021.* (from mkl<=2021.4.0,>=2021.1.1->torch==2.3.0->torchvision==0.18.0)
  Downloading tbb-2021.13.1-py3-none-win_amd64.whl.metadata (1.1 kB)
Requirement already satisfied: MarkupSafe>=2.0 in c:\users\jmzhu\anaconda3\envs\mnist\lib\site-packages (from jinja2->torch==2.3.0->torchvision==0.18.0) (3.0.2)
Requirement already satisfied: mpmath<1.4,>=1.1.0 in c:\users\jmzhu\anaconda3\envs\mnist\lib\site-packages (from sympy->torch==2.3.0->torchvision==0.18.0) (1.3.0)
Downloading torchvision-0.18.0-cp39-cp39-win_amd64.whl (1.2 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.2/1.2 MB 261.7 kB/s eta 0:00:00
Downloading torch-2.3.0-cp39-cp39-win_amd64.whl (159.7 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 159.7/159.7 MB 8.9 MB/s eta 0:00:00
Downloading mkl-2021.4.0-py2.py3-none-win_amd64.whl (228.5 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 228.5/228.5 MB 8.2 MB/s eta 0:00:00
Downloading intel_openmp-2021.4.0-py2.py3-none-win_amd64.whl (3.5 MB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.5/3.5 MB 12.2 MB/s eta 0:00:00
Downloading tbb-2021.13.1-py3-none-win_amd64.whl (286 kB)
Installing collected packages: tbb, intel-openmp, mkl, torch, torchvision
  Attempting uninstall: torch
    Found existing installation: torch 2.7.0
    Uninstalling torch-2.7.0:
      Successfully uninstalled torch-2.7.0
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
torchaudio 0.12.1+cpu requires torch==1.12.1, but you have torch 2.3.0 which is incompatible.
Successfully installed intel-openmp-2021.4.0 mkl-2021.4.0 tbb-2021.13.1 torch-2.3.0 torchvision-0.18.0

(mnist) C:\Users\jmzhu>jupyter notebook
[I 2025-05-08 14:23:01.125 ServerApp] jupyter_lsp | extension was successfully linked.
[I 2025-05-08 14:23:01.131 ServerApp] jupyter_server_terminals | extension was successfully linked.
[I 2025-05-08 14:23:01.140 ServerApp] jupyterlab | extension was successfully linked.
[I 2025-05-08 14:23:01.147 ServerApp] notebook | extension was successfully linked.
[I 2025-05-08 14:23:01.443 ServerApp] notebook_shim | extension was successfully linked.
[I 2025-05-08 14:23:01.474 ServerApp] notebook_shim | extension was successfully loaded.
[I 2025-05-08 14:23:01.476 ServerApp] jupyter_lsp | extension was successfully loaded.
[I 2025-05-08 14:23:01.477 ServerApp] jupyter_s。。。。

大神的jupyter notebook可以编译运行了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值