在Arm/Linux下安装python的pytorch库

  • Post author:
  • Post category:linux




在Arm/Linux下安装python的pytorch库

通过pip安装torch库,报以下错误。

nvidia@nx:~/pengjing/pytorch_packget$ sudo pip3 install torch
The directory '/home/nvidia/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/nvidia/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting torch
  Could not find a version that satisfies the requirement torch (from versions: )
No matching distribution found for torch

根据最终找到的解决办法,问题可能出在pip的版本较低。导致无法自动安装 torch 库。



分析问题过程:

搜索到相关链接


arm64下安装pytorch,torchvision,torchaudio以及它们之间的版本对应关系

根据该文档的要求的步骤一步步做,下载好torch-1.11.0-cp38-cp38-manylinux2014_aarch64.whl与torchvision-0.12.0-cp38-cp38-manylinux2014_aarch64.whl文件,并进行pip安装时,报以下错误:

nvidia@nx:~/pengjing/pytorch_packget$ sudo pip3 install torch-1.11.0-cp37-cp37m-manylinux2014_aarch64.whl 
The directory '/home/nvidia/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/nvidia/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
torch-1.11.0-cp37-cp37m-manylinux2014_aarch64.whl is not a supported wheel on this platform.

提示说该轮子不被该平台支持。

做到这,我就纳闷了,明明是aarch64架构python轮子,为什么说不被支持呢? 我想这个包肯定是没什么问题,并且可以用于ARM平台上,应该是漏掉了什么。

想到这我,我就去 torch-1.11.0-cp37-cp37m-manylinux2014_aarch64.whl 这个库的

下载地址

,找寻线索,希望能够找到背后的原因。

在这个下载地址页面,我看到了这样一句话

Download the file for your platform. If you’re not sure which to choose, learn more about

installing packages

.

哈哈,这不就是我当前遇到的问题嘛,随即进入

installing packages

.这个链接。

其实进到这个页面,也摸不到方向,但可以肯定的是问题可以在这个页面里搜索到解决方案,以及问题背后的原因

然后我又看了看这个库文件名称 torch-1.11.0-cp37-cp37m-manylinux2014_aarch64.whl(因为库文件名称往往对应于被支持平台的信息);其中有关键字:cp37、cp37m、manylinux2014、aarch64。

cp37、cp37m:python3.7版本

aarch64:库运行平台架构。这个可以通过 uname -a 命令可以看出linux平台架构(核对过,是aarch64架构)

manylinux2014:这个关键字目前还不知道含义。

随即进入

installing packages

检索(右上角搜索框) manylinux2014 的含义,检索出如下内容:

Manylinux compatibility support

哈哈,看到没,这个manylinux2014是要求pip >=19.3、auditwheel>=3.0.0。我马上通过

pip3 -V

或者

pip3 show pip

看了下自己pip的版本。

在这里插入图片描述


瞬间发现我的pip版本原来是9.0.1,不能满足 manylinux2014 的要求

。解决办法显而易见就是:

更新 pip 版本

pip是一个python的包管理工具,实际上它也可以被看待为是一个包。而且可以通过

vi /usr/bin/pip

编辑pip所代表的python版本

在这里插入图片描述



解决过程:

参考文章:


使用Python pip怎么升级pip

  1. 更新pip
python3.7 -m pip install --upgrade pip

2.查看pip版本

pip3 show pip

3.安装torch库

sudo pip3 install torch-1.11.0-cp38-cp38-manylinux2014_aarch64.whl
sudo pip3 install torchvision-0.12.0-cp38-cp38-manylinux2014_aarch64.whl
sudo pip3 install torchaudio

4.结果顺利安装成功
在这里插入图片描述



版权声明:本文为ReturningProdigal原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。