因为要在树莓派上部署模型,所以要用到Tesnorflow,对于树莓派来说,官方推荐下载解释器tflite-runtime。 需要使用虚拟环境下载安装,因为树莓派系统里不许使用pip(害怕和apt起冲突),用了就会报错:
× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
python3-xyz, where xyz is the package you are trying to
install.
If you wish to install a non-Debian-packaged Python package,
create a virtual environment using python3 -m venv path/to/venv.
Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
sure you have python3-full installed.
If you wish to install a non-Debian packaged Python application,
it may be easiest to use pipx install xyz, which will manage a
virtual environment for you. Make sure you have pipx installed.
See /usr/share/doc/python3.11/README.venv for more information.
note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.
一、在python3.7虚拟环境下载 .whl并安装
这个方法失败了,查看自己匹配的版本,我使用python3.7,再使用pip debug --verbose命令即可查看自己的树莓派的平台。
下载并安装(虚拟环境下),然后报错:缺失ssl模块。
python3.7 -m vnev tflite
source tflite/bin/activate
wget https://dl.google.com/coral/python/tflite_runtime-2.1.0.post1-cp37-cp37m-linux_aarch64.whl
sudo pip install tflite_runtime-2.1.0.post1-cp37-cp37m-linux_aarch64.whl
二、在python3.11虚拟环境下载tflite-runtime
这个方法也失败了,在python3.11创建虚拟环境里下载解释器,下载速度慢( 树莓派 pip
使用 piwheels.org 作为附加索引,服务器在英国,有方法可以设置取消此索引),下载完成后报错:软件包不适合此架构。
树莓派4B是arm64位的架构,我安装的32位树莓派系统,装的32位python,理论上应该兼容的,触及到我知识盲区了hhhh。
python -m venv tflite
source tflite/bin/activate
pip install tflite-runtime
三、用virtualenv虚拟环境下载tflite-runtime
重新给树莓派烧录了64位的操作系统,在网上看到的下载方法,用virtualenv。
下载virtualenv,创建虚拟环境并激活,加入--system-site-packages
选项,这会允许虚拟环境访问系统Python环境中已安装的包和库(这句话是偷的),然后就可以使用pip3安装了。
sudo apt-get install virtualenv
virtualenv 51env --system-site-packages
source 51env/bin/activate
pip3 install --extra-index-url https://google-coral.github.io/py-repo/ tflite_runtime
方法三参考(搬运于):在最新raspberry pi 64-bit os上安装tflite-runtime_see pep 668 for the detailed specification.-CSDN博客