树莓派安装pytorch环境记录

2024-05-21 15:53:22 浏览数 (2)

查看系统架构

代码语言:javascript复制
root@raspberrypi:~# uname -a
Linux raspberrypi 5.10.17-v7l  #1414 SMP Fri Apr 30 13:20:47 BST 2021 armv7l GNU/Linux

安装torch和torchvision

torch.maku.ml/whl/stable.…

安装torch

代码语言:javascript复制
root@raspberrypi:~# pip install torch -f https://torch.maku.ml/whl/stable.html
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Looking in links: https://torch.maku.ml/whl/stable.html
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0xb43bea90>: Failed to establish a new connection: [Errno 101] Network is unreachable')': /whl/stable.html
Collecting torch
  Downloading https://github.com/KumaTea/pytorch-arm/releases/download/v1.8.1/torch-1.8.1-cp37-cp37m-linux_armv7l.whl (41.1 MB)

下载有点慢,可以先本地下载好github.com/KumaTea/pyt…,再离线安装

代码语言:javascript复制
root@raspberrypi:~# pip install ./torch-1.8.1-cp37-cp37m-linux_armv7l.whl
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Processing /edge/torch-1.8.1-cp37-cp37m-linux_armv7l.whl
Collecting typing-extensions
  Downloading https://www.piwheels.org/simple/typing-extensions/typing_extensions-4.2.0-py3-none-any.whl (24 kB)
Requirement already satisfied: numpy in /usr/lib/python3/dist-packages (from torch==1.8.1) (1.16.2)
Installing collected packages: typing-extensions, torch
Successfully installed torch-1.8.1 typing-extensions-4.2.0

安装torchvision

代码语言:javascript复制
root@raspberrypi:~# pip install torchvision -f https://torch.maku.ml/whl/stable.html
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Looking in links: https://torch.maku.ml/whl/stable.html
...

同样下载有点慢,可以先本地下载好github.com/KumaTea/pyt…,再离线安装

代码语言:javascript复制
root@raspberrypi:~# pip install /edge/torchvision-0.9.1-cp37-cp37m-linux_armv7l.whl
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Processing /edge/torchvision-0.9.1-cp37-cp37m-linux_armv7l.whl
Requirement already satisfied: pillow>=4.1.1 in /usr/lib/python3/dist-packages (from torchvision==0.9.1) (5.4.1)
Requirement already satisfied: torch in /usr/local/lib/python3.7/dist-packages (from torchvision==0.9.1) (1.8.1)
Requirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (from torchvision==0.9.1) (1.21.6)
Requirement already satisfied: typing-extensions in /usr/local/lib/python3.7/dist-packages (from torch->torchvision==0.9.1) (4.2.0)
Installing collected packages: torchvision
Successfully installed torchvision-0.9.1

测试torch

代码语言:javascript复制
root@raspberrypi:~# python3
Python 3.7.3 (default, Jan 22 2021, 20:04:44)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> torch.distributed.is_available()
True

问题

xxxx is not a supported wheel on this platform

系统架构、python版本等与安装包不匹配导致的。

查看当前python版本适配的版本

代码语言:javascript复制
root@raspberrypi:~# pip debug --verbose
WARNING: This command is only meant for debugging. Do not use this with automation for parsing and getting these details, since the output and options of this command may change without notice.
pip version: pip 22.1.1 from /usr/local/lib/python3.7/dist-packages/pip (python 3.7)
sys.version: 3.7.3 (default, Jan 22 2021, 20:04:44)
[GCC 8.3.0]
sys.executable: /usr/bin/python3
sys.getdefaultencoding: utf-8
sys.getfilesystemencoding: utf-8
locale.getpreferredencoding: UTF-8
sys.platform: linux
sys.implementation:
  name: cpython
'cert' config value: global
REQUESTS_CA_BUNDLE: None
CURL_CA_BUNDLE: None
pip._vendor.certifi.where(): /usr/local/lib/python3.7/dist-packages/pip/_vendor/certifi/cacert.pem
pip._vendor.DEBUNDLED: False
vendored library versions:
  CacheControl==0.12.11
  colorama==0.4.4
  distlib==0.3.3
  distro==1.7.0
  html5lib==1.1
  msgpack==1.0.3 (Unable to locate actual module version, using vendor.txt specified version)
  packaging==21.3
  pep517==0.12.0
  platformdirs==2.5.2
  pyparsing==3.0.8
  requests==2.27.1
  certifi==2021.10.08
  chardet==4.0.0
  idna==3.3
  urllib3==1.26.9
  rich==12.2.0 (Unable to locate actual module version, using vendor.txt specified version)
  pygments==2.11.2
  typing_extensions==4.2.0 (Unable to locate actual module version, using vendor.txt specified version)
  resolvelib==0.8.1
  setuptools==44.0.0 (Unable to locate actual module version, using vendor.txt specified version)
  six==1.16.0
  tenacity==8.0.1 (Unable to locate actual module version, using vendor.txt specified version)
  tomli==2.0.1
  webencodings==0.5.1 (Unable to locate actual module version, using vendor.txt specified version)
Compatible tags: 248
  cp37-cp37m-manylinux_2_28_armv7l
  cp37-cp37m-manylinux_2_27_armv7l
  cp37-cp37m-manylinux_2_26_armv7l
  cp37-cp37m-manylinux_2_25_armv7l
  cp37-cp37m-manylinux_2_24_armv7l
  cp37-cp37m-manylinux_2_23_armv7l
  cp37-cp37m-manylinux_2_22_armv7l
  cp37-cp37m-manylinux_2_21_armv7l
  cp37-cp37m-manylinux_2_20_armv7l
  cp37-cp37m-manylinux_2_19_armv7l
  cp37-cp37m-manylinux_2_18_armv7l
  cp37-cp37m-manylinux_2_17_armv7l
  cp37-cp37m-manylinux2014_armv7l
  cp37-cp37m-linux_armv7l
  cp37-abi3-manylinux_2_28_armv7l
  cp37-abi3-manylinux_2_27_armv7l
  cp37-abi3-manylinux_2_26_armv7l
  cp37-abi3-manylinux_2_25_armv7l
  cp37-abi3-manylinux_2_24_armv7l
  cp37-abi3-manylinux_2_23_armv7l
  cp37-abi3-manylinux_2_22_armv7l
  cp37-abi3-manylinux_2_21_armv7l
  cp37-abi3-manylinux_2_20_armv7l
  cp37-abi3-manylinux_2_19_armv7l
  cp37-abi3-manylinux_2_18_armv7l
  cp37-abi3-manylinux_2_17_armv7l
  cp37-abi3-manylinux2014_armv7l
  cp37-abi3-linux_armv7l
  cp37-none-manylinux_2_28_armv7l
  cp37-none-manylinux_2_27_armv7l
  cp37-none-manylinux_2_26_armv7l
  cp37-none-manylinux_2_25_armv7l
  cp37-none-manylinux_2_24_armv7l
  cp37-none-manylinux_2_23_armv7l
  cp37-none-manylinux_2_22_armv7l
  cp37-none-manylinux_2_21_armv7l
  cp37-none-manylinux_2_20_armv7l
  cp37-none-manylinux_2_19_armv7l
  cp37-none-manylinux_2_18_armv7l
  cp37-none-manylinux_2_17_armv7l
  cp37-none-manylinux2014_armv7l
  cp37-none-linux_armv7l
  cp36-abi3-manylinux_2_28_armv7l
  cp36-abi3-manylinux_2_27_armv7l
  cp36-abi3-manylinux_2_26_armv7l
  cp36-abi3-manylinux_2_25_armv7l
  cp36-abi3-manylinux_2_24_armv7l
  cp36-abi3-manylinux_2_23_armv7l
  cp36-abi3-manylinux_2_22_armv7l
  cp36-abi3-manylinux_2_21_armv7l
  cp36-abi3-manylinux_2_20_armv7l
  cp36-abi3-manylinux_2_19_armv7l
  cp36-abi3-manylinux_2_18_armv7l
  cp36-abi3-manylinux_2_17_armv7l
  cp36-abi3-manylinux2014_armv7l
  cp36-abi3-linux_armv7l
  cp35-abi3-manylinux_2_28_armv7l
  cp35-abi3-manylinux_2_27_armv7l
  cp35-abi3-manylinux_2_26_armv7l
  cp35-abi3-manylinux_2_25_armv7l
  cp35-abi3-manylinux_2_24_armv7l
  cp35-abi3-manylinux_2_23_armv7l
  cp35-abi3-manylinux_2_22_armv7l
  cp35-abi3-manylinux_2_21_armv7l
  cp35-abi3-manylinux_2_20_armv7l
  cp35-abi3-manylinux_2_19_armv7l
  cp35-abi3-manylinux_2_18_armv7l
  cp35-abi3-manylinux_2_17_armv7l
  cp35-abi3-manylinux2014_armv7l
  cp35-abi3-linux_armv7l
  cp34-abi3-manylinux_2_28_armv7l
  cp34-abi3-manylinux_2_27_armv7l
  cp34-abi3-manylinux_2_26_armv7l
  cp34-abi3-manylinux_2_25_armv7l
  cp34-abi3-manylinux_2_24_armv7l
  cp34-abi3-manylinux_2_23_armv7l
  cp34-abi3-manylinux_2_22_armv7l
  cp34-abi3-manylinux_2_21_armv7l
  cp34-abi3-manylinux_2_20_armv7l
  cp34-abi3-manylinux_2_19_armv7l
  cp34-abi3-manylinux_2_18_armv7l
  cp34-abi3-manylinux_2_17_armv7l
  cp34-abi3-manylinux2014_armv7l
  cp34-abi3-linux_armv7l
  cp33-abi3-manylinux_2_28_armv7l
  cp33-abi3-manylinux_2_27_armv7l
  cp33-abi3-manylinux_2_26_armv7l
  cp33-abi3-manylinux_2_25_armv7l
  cp33-abi3-manylinux_2_24_armv7l
  cp33-abi3-manylinux_2_23_armv7l
  cp33-abi3-manylinux_2_22_armv7l
  cp33-abi3-manylinux_2_21_armv7l
  cp33-abi3-manylinux_2_20_armv7l
  cp33-abi3-manylinux_2_19_armv7l
  cp33-abi3-manylinux_2_18_armv7l
  cp33-abi3-manylinux_2_17_armv7l
  cp33-abi3-manylinux2014_armv7l
  cp33-abi3-linux_armv7l
  cp32-abi3-manylinux_2_28_armv7l
  cp32-abi3-manylinux_2_27_armv7l
  cp32-abi3-manylinux_2_26_armv7l
  cp32-abi3-manylinux_2_25_armv7l
  cp32-abi3-manylinux_2_24_armv7l
  cp32-abi3-manylinux_2_23_armv7l
  cp32-abi3-manylinux_2_22_armv7l
  cp32-abi3-manylinux_2_21_armv7l
  cp32-abi3-manylinux_2_20_armv7l
  cp32-abi3-manylinux_2_19_armv7l
  cp32-abi3-manylinux_2_18_armv7l
  cp32-abi3-manylinux_2_17_armv7l
  cp32-abi3-manylinux2014_armv7l
  cp32-abi3-linux_armv7l
  py37-none-manylinux_2_28_armv7l
  py37-none-manylinux_2_27_armv7l
  py37-none-manylinux_2_26_armv7l
  py37-none-manylinux_2_25_armv7l
  py37-none-manylinux_2_24_armv7l
  py37-none-manylinux_2_23_armv7l
  py37-none-manylinux_2_22_armv7l
  py37-none-manylinux_2_21_armv7l
  py37-none-manylinux_2_20_armv7l
  py37-none-manylinux_2_19_armv7l
  py37-none-manylinux_2_18_armv7l
  py37-none-manylinux_2_17_armv7l
  py37-none-manylinux2014_armv7l
  py37-none-linux_armv7l
  py3-none-manylinux_2_28_armv7l
  py3-none-manylinux_2_27_armv7l
  py3-none-manylinux_2_26_armv7l
  py3-none-manylinux_2_25_armv7l
  py3-none-manylinux_2_24_armv7l
  py3-none-manylinux_2_23_armv7l
  py3-none-manylinux_2_22_armv7l
  py3-none-manylinux_2_21_armv7l
  py3-none-manylinux_2_20_armv7l
  py3-none-manylinux_2_19_armv7l
  py3-none-manylinux_2_18_armv7l
  py3-none-manylinux_2_17_armv7l
  py3-none-manylinux2014_armv7l
  py3-none-linux_armv7l
  py36-none-manylinux_2_28_armv7l
  py36-none-manylinux_2_27_armv7l
  py36-none-manylinux_2_26_armv7l
  py36-none-manylinux_2_25_armv7l
  py36-none-manylinux_2_24_armv7l
  py36-none-manylinux_2_23_armv7l
  py36-none-manylinux_2_22_armv7l
  py36-none-manylinux_2_21_armv7l
  py36-none-manylinux_2_20_armv7l
  py36-none-manylinux_2_19_armv7l
  py36-none-manylinux_2_18_armv7l
  py36-none-manylinux_2_17_armv7l
  py36-none-manylinux2014_armv7l
  py36-none-linux_armv7l
  py35-none-manylinux_2_28_armv7l
  py35-none-manylinux_2_27_armv7l
  py35-none-manylinux_2_26_armv7l
  py35-none-manylinux_2_25_armv7l
  py35-none-manylinux_2_24_armv7l
  py35-none-manylinux_2_23_armv7l
  py35-none-manylinux_2_22_armv7l
  py35-none-manylinux_2_21_armv7l
  py35-none-manylinux_2_20_armv7l
  py35-none-manylinux_2_19_armv7l
  py35-none-manylinux_2_18_armv7l
  py35-none-manylinux_2_17_armv7l
  py35-none-manylinux2014_armv7l
  py35-none-linux_armv7l
  py34-none-manylinux_2_28_armv7l
  py34-none-manylinux_2_27_armv7l
  py34-none-manylinux_2_26_armv7l
  py34-none-manylinux_2_25_armv7l
  py34-none-manylinux_2_24_armv7l
  py34-none-manylinux_2_23_armv7l
  py34-none-manylinux_2_22_armv7l
  py34-none-manylinux_2_21_armv7l
  py34-none-manylinux_2_20_armv7l
  py34-none-manylinux_2_19_armv7l
  py34-none-manylinux_2_18_armv7l
  py34-none-manylinux_2_17_armv7l
  py34-none-manylinux2014_armv7l
  py34-none-linux_armv7l
  py33-none-manylinux_2_28_armv7l
  py33-none-manylinux_2_27_armv7l
  py33-none-manylinux_2_26_armv7l
  py33-none-manylinux_2_25_armv7l
  py33-none-manylinux_2_24_armv7l
  py33-none-manylinux_2_23_armv7l
  py33-none-manylinux_2_22_armv7l
  py33-none-manylinux_2_21_armv7l
  py33-none-manylinux_2_20_armv7l
  py33-none-manylinux_2_19_armv7l
  py33-none-manylinux_2_18_armv7l
  py33-none-manylinux_2_17_armv7l
  py33-none-manylinux2014_armv7l
  py33-none-linux_armv7l
  py32-none-manylinux_2_28_armv7l
  py32-none-manylinux_2_27_armv7l
  py32-none-manylinux_2_26_armv7l
  py32-none-manylinux_2_25_armv7l
  py32-none-manylinux_2_24_armv7l
  py32-none-manylinux_2_23_armv7l
  py32-none-manylinux_2_22_armv7l
  py32-none-manylinux_2_21_armv7l
  py32-none-manylinux_2_20_armv7l
  py32-none-manylinux_2_19_armv7l
  py32-none-manylinux_2_18_armv7l
  py32-none-manylinux_2_17_armv7l
  py32-none-manylinux2014_armv7l
  py32-none-linux_armv7l
  py31-none-manylinux_2_28_armv7l
  py31-none-manylinux_2_27_armv7l
  py31-none-manylinux_2_26_armv7l
  py31-none-manylinux_2_25_armv7l
  py31-none-manylinux_2_24_armv7l
  py31-none-manylinux_2_23_armv7l
  py31-none-manylinux_2_22_armv7l
  py31-none-manylinux_2_21_armv7l
  py31-none-manylinux_2_20_armv7l
  py31-none-manylinux_2_19_armv7l
  py31-none-manylinux_2_18_armv7l
  py31-none-manylinux_2_17_armv7l
  py31-none-manylinux2014_armv7l
  py31-none-linux_armv7l
  py30-none-manylinux_2_28_armv7l
  py30-none-manylinux_2_27_armv7l
  py30-none-manylinux_2_26_armv7l
  py30-none-manylinux_2_25_armv7l
  py30-none-manylinux_2_24_armv7l
  py30-none-manylinux_2_23_armv7l
  py30-none-manylinux_2_22_armv7l
  py30-none-manylinux_2_21_armv7l
  py30-none-manylinux_2_20_armv7l
  py30-none-manylinux_2_19_armv7l
  py30-none-manylinux_2_18_armv7l
  py30-none-manylinux_2_17_armv7l
  py30-none-manylinux2014_armv7l
  py30-none-linux_armv7l
  cp37-none-any
  py37-none-any
  py3-none-any
  py36-none-any
  py35-none-any
  py34-none-any
  py33-none-any
  py32-none-any
  py31-none-any
  py30-none-any

RuntimeError: module compiled against API version 0xe but this version of numpy is 0xd

numpy版本过低的原因 查看numpy版本

代码语言:javascript复制
root@raspberrypi:~# pip show numpy
Name: numpy
Version: 1.16.2
Summary: NumPy is the fundamental package for array computing with Python.
Home-page: https://www.numpy.org
Author: Travis E. Oliphant et al.
Author-email:
License: BSD
Location: /usr/lib/python3/dist-packages
Requires:
Required-by: microdotphat, scrollphathd, sense-hat, torch

更新numpy

代码语言:javascript复制
root@raspberrypi:~# pip install -U numpy
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: numpy in /usr/lib/python3/dist-packages (1.16.2)
Collecting numpy

...

Successfully built numpy
Installing collected packages: numpy
  Attempting uninstall: numpy
    Found existing installation: numpy 1.16.2
    Uninstalling numpy-1.16.2:
      Successfully uninstalled numpy-1.16.2
Successfully installed numpy-1.21.6

zhuanlan.zhihu.com/p/446627852 blog.csdn.net/happywlg123…

0 人点赞