最近因为一些原因需要用到tflite-support这个库,但是当使用pip安装时出现错误,具体错误如下:
C:\Users\xxxxx\AppData\Local\Programs\Python\Python3x\lib\site-packages\setuptools\command\build_py.py:202: SetuptoolsDeprecationWarning: Installing 'tflite_support.flatbuffers' as data is deprecated, please list it in `packages`.
!!
############################
# Package would be ignored #
############################
Python recognizes 'tflite_support.flatbuffers' as an importable package,
but it is not listed in the `packages` configuration of setuptools.
'tflite_support.flatbuffers' has been automatically added to the distribution only
because it may contain data files, but this behavior is likely to change
in future versions of setuptools (and therefore is considered deprecated).
Please make sure that 'tflite_support.flatbuffers' is included as a package by using
the `packages` configuration field or the proper discovery methods
(for example by using `find_namespace_packages(...)`/`find_namespace:`
instead of `find_packages(...)`/`find:`).
You can read more about "package discovery" and "data files" on setuptools
documentation page.
!!
check.warn(importable)
copying tflite_support\metadata_schema.fbs -> build\lib.win-amd64-cpython-310\tflite_support
creating build\lib.win-amd64-cpython-310\tflite_support\flatbuffers
copying tflite_support\flatbuffers\__init__.py -> build\lib.win-amd64-cpython-310\tflite_support\flatbuffers
copying tflite_support\flatbuffers\builder.py -> build\lib.win-amd64-cpython-310\tflite_support\flatbuffers
copying tflite_support\flatbuffers\compat.py -> build\lib.win-amd64-cpython-310\tflite_support\flatbuffers
copying tflite_support\flatbuffers\encode.py -> build\lib.win-amd64-cpython-310\tflite_support\flatbuffers
copying tflite_support\flatbuffers\number_types.py -> build\lib.win-amd64-cpython-310\tflite_support\flatbuffers
copying tflite_support\flatbuffers\packer.py -> build\lib.win-amd64-cpython-310\tflite_support\flatbuffers
copying tflite_support\flatbuffers\table.py -> build\lib.win-amd64-cpython-310\tflite_support\flatbuffers
copying tflite_support\flatbuffers\util.py -> build\lib.win-amd64-cpython-310\tflite_support\flatbuffers
running build_ext
building '_pywrap_codegen' extension
error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools": https://visualstudio.microsoft.com/visual-cpp-build-tools/
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure
× Encountered error while trying to install package.
╰─> tflite-support
note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.
这是因为tflite-support没有官方的Windows发行版,因此在Windows系统上需要自行编译
从输出可以看到:error: Microsoft Visual C++ 14.0 or greater is required. Get it with “Microsoft C++ Build Tools”: https://visualstudio.microsoft.com/visual-cpp-build-tools/
即本地没有C++编译器,因此我们只需安装C++编译器即可:https://visualstudio.microsoft.com/zh-hant/visual-cpp-build-tools
在安装时只需要勾选 使用C++的桌面开发 ,无需勾选其余项目
在安装后使用命令 pip install tflite-support 重新安装即可