ERROR: Could not install packages due to an OSError: [Errno 2] No such file or directory:错误解决方法

在windows10上用pip命令pip install torch==1.7.1+cu101 torchvision==0.8.2+cu101 torchaudio==0.7.2 -f https://download.pytorch.org/whl/torch_stable.html安装pytorch时遇到如下问题:

PS C:\Users\mgn10> pip install torch==1.7.1+cu101 torchvision==0.8.2+cu101 torchaudio==0.7.2 -f https://download.pytorch.org/whl/torch_stable.html
Looking in links: https://download.pytorch.org/whl/torch_stable.html
Collecting torch==1.7.1+cu101
  Using cached https://download.pytorch.org/whl/cu101/torch-1.7.1%2Bcu101-cp37-cp37m-win_amd64.whl (1204.8 MB)
Collecting torchvision==0.8.2+cu101
  Using cached https://download.pytorch.org/whl/cu101/torchvision-0.8.2%2Bcu101-cp37-cp37m-win_amd64.whl (1.5 MB)
Collecting torchaudio==0.7.2
  Using cached https://download.pytorch.org/whl/torchaudio-0.7.2-cp37-none-win_amd64.whl (103 kB)
Requirement already satisfied: typing-extensions in c:\users\mgn10\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from torch==1.7.1+cu101) (3.10.0.0)
Requirement already satisfied: numpy in c:\users\mgn10\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from torch==1.7.1+cu101) (1.20.3)
Requirement already satisfied: pillow>=4.1.1 in c:\users\mgn10\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from torchvision==0.8.2+cu101) (8.2.0)
Installing collected packages: torch, torchvision, torchaudio
ERROR: Could not install packages due to an OSError: [Errno 2] No such file or directory: 'C:\\Users\\mgn10\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python37\\site-packages\\caffe2\\python\\serialized_test\\data\\operator_test\\collect_and_distribute_fpn_rpn_proposals_op_test.test_collect_and_dist.zip'

在reddit上找到了能用的解决办法。
错误的原因大概是路径长度超过256系统报错,所以我们需要做的
1.补上collect_and_distribute_fpn_rpn_proposals_op_test.test_collect_and_dist.zip文件。
2.改一下系统内部设置
具体方法
1.在这里下载缺失文件,放到缺失的地方。
2.打开powershell,输入regedit.exe打开注册表编辑器,定位到HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem 双击 LongPathsEnabled,把0改为1,保存关闭。
3. 重新运行安装命令。

PS C:\Users\mgn10> pip install torch==1.7.1+cu101 torchvision==0.8.2+cu101 torchaudio==0.7.2 -f https://download.pytorch.org/whl/torch_stable.html
Looking in links: https://download.pytorch.org/whl/torch_stable.html
Collecting torch==1.7.1+cu101
  Using cached https://download.pytorch.org/whl/cu101/torch-1.7.1%2Bcu101-cp37-cp37m-win_amd64.whl (1204.8 MB)
Collecting torchvision==0.8.2+cu101
  Using cached https://download.pytorch.org/whl/cu101/torchvision-0.8.2%2Bcu101-cp37-cp37m-win_amd64.whl (1.5 MB)
Collecting torchaudio==0.7.2
  Using cached https://download.pytorch.org/whl/torchaudio-0.7.2-cp37-none-win_amd64.whl (103 kB)
Requirement already satisfied: typing-extensions in c:\users\mgn10\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from torch==1.7.1+cu101) (3.10.0.0)
Requirement already satisfied: numpy in c:\users\mgn10\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from torch==1.7.1+cu101) (1.20.3)
Requirement already satisfied: pillow>=4.1.1 in c:\users\mgn10\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages (from torchvision==0.8.2+cu101) (8.2.0)
Installing collected packages: torch, torchvision, torchaudio
  WARNING: The scripts convert-caffe2-to-onnx.exe and convert-onnx-to-caffe2.exe are installed in 'C:\Users\mgn10\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\Scripts' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed torch-1.7.1+cu101 torchaudio-0.7.2 torchvision-0.8.2+cu101
PS C:\Users\mgn10> python
Python 3.7.9 (tags/v3.7.9:13c94747c7, Aug 17 2020, 16:30:00) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> torch.cuda.is_available()
True
>>> exit()

重新安装成功。

你可能感兴趣的:(报错)