@FubiraiHan

Are you sure you want to delete the question?

Leaving a resolved question undeleted may help others!

torchのimportができない

Q&A

Closed

以下のエラーについて解決策を知りたいです。
1:pythonでtorchをインポートするとエラーが発生します。

$ python
Python 3.11.14 (main, Nov  4 2025, 13:03:30) [GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
Bus error (core dumped)

2:また、cudnnをインストールしようとすると以下のようなエラーが発生し、wslがクラッシュします。

$ sudo dpkg -i cudnn-local-repo-ubuntu2404-9.15.0_1.0-1_amd64.deb
(Reading database ... 48077 files and directories currently installed.)
Preparing to unpack cudnn-local-repo-ubuntu2404-9.15.0_1.0-1_amd64.deb ...
Unpacking cudnn-local-repo-ubuntu2404-9.15.0 (1.0-1) over (1.0-1) ...
dpkg-deb (subprocess): cannot copy archive member from 'cudnn-local-repo-ubuntu2404-9.15.0_1.0-1_amd64.deb' to decompressor pipe: failed to read (Input/output error)
dpkg: error processing archive cudnn-local-repo-ubuntu2404-9.15.0_1.0-1_amd64.deb (--install):
 cannot copy extracted data for './var/cudnn-local-repo-ubuntu2404-9.15.0/libcudnn9-cuda-13_9.15.0.58-1_amd64.deb' to '/var/cudnn-local-repo-ubuntu2404-9.15.0/libcudnn9-cuda-13_9.15.0.58-1_amd64.deb.dpkg-new': failed to write (Input/output error)
dpkg: error while cleaning up:
 unable to remove newly-extracted version of '/var/cudnn-local-repo-ubuntu2404-9.15.0/libcudnn9-cuda-13_9.15.0.58-1_amd64.deb': Input/output error
dpkg: error while cleaning up:
 unable to remove backup copy of '/var/cudnn-local-repo-ubuntu2404-9.15.0/libcudnn9-cuda-12_9.15.0.57-1_amd64.deb': Input/output error
dpkg: error while cleaning up:
 unable to remove backup copy of '/var/cudnn-local-repo-ubuntu2404-9.15.0/cudnn_9.15.0-1_amd64.deb': Input/output error
 #以下略

環境は以下のとおりです
os: windows wsl2 ubuntu 24.04
python:3.11.14(pyenvを使用)
torch:2.9.0+cu130

$ nvidia-smi
Wed Nov  5 21:58:34 2025
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 580.95.02              Driver Version: 581.42         CUDA Version: 13.0     |
+-----------------------------------------+------------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|=========================================+========================+======================|
|   0  NVIDIA GeForce RTX 3070        On  |   00000000:01:00.0  On |                  N/A |
|  0%   55C    P0             51W /  220W |    1894MiB /   8192MiB |      1%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+

+-----------------------------------------------------------------------------------------+
| Processes:                                                                              |
|  GPU   GI   CI              PID   Type   Process name                        GPU Memory |
|        ID   ID                                                               Usage      |
|=========================================================================================|
|    0   N/A  N/A             349      G   /Xwayland                             N/A      |
+-----------------------------------------------------------------------------------------+
$ nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2025 NVIDIA Corporation
Built on Wed_Aug_20_01:58:59_PM_PDT_2025
Cuda compilation tools, release 13.0, V13.0.88
Build cuda_13.0.r13.0/compiler.36424714_0

cuDNNは以前入れたつもりでしたが、こちらの記事にあったcuDnnのバージョン確認方法を取ろうとしてもそもそも/usr/local/cuda-13.0/に/include/のフォルダがなかったため、確認できませんでした。

またCUDA自体を除去しようとしても

"cuda-repo-wsl-ubuntu-13-0-local needs to be reinstalled, but I can't find an archive for it."

というエラーが出て実行できませんでした。

以上よろしくお願いいたします。

0 likes

1Answer

こんにちは!

WSL2はホストマシンのグラフィックカードドライバーを使用するため、CUDAとcuDNNを今すぐインストールする必要はありません。

エラーは環境の破損が原因である可能性があります。ホストマシンのグラフィックカードドライバーを確認して更新し、WSLを再インストールすることをお勧めします。

私はかつて WSL で機械学習プロジェクトを実行していましたが、そのときに参照した Web ページは次のとおりです: Getting Started with CUDA on WSL 2

これが役に立つことを願います。

0Like

Your answer might help someone💌