本文主要是介绍fix --nanopb_out: protoc-gen-nanopb: Plugin failed with status code 1.,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
错误打印
Traceback (most recent call last):File "/home/mi/local/sdk-for-device/proto_buf/0.3.9.6/generator/nanopb_generator.py", line 37, in <module>from .proto import nanopb_pb2, plugin_pb2
ImportError: attempted relative import with no known parent packageDuring handling of the above exception, another exception occurred:Traceback (most recent call last):File "/home/mi/local/sdk-for-device/proto_buf/0.3.9.6/generator/nanopb_generator.py", line 57, in <module>import proto.nanopb_pb2 as nanopb_pb2File "/home/mi/local/sdk-for-device/proto_buf/0.3.9.6/generator/proto/nanopb_pb2.py", line 34, in <module>_descriptor.EnumValueDescriptor(File "/home/mi/.local/lib/python3.8/site-packages/google/protobuf/descriptor.py", line 789, in __new___message.Message._CheckCalledFromGeneratedFile()
TypeError: Descriptors cannot be created directly.
If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.
If you cannot immediately regenerate your protos, some other possible workarounds are:1. Downgrade the protobuf package to 3.20.x or lower.2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).More information: https://developers.google.com/protocol-buffers/docs/news/2022-05-06#python-updates
--nanopb_out: protoc-gen-nanopb: Plugin failed with status code 1.
make: *** [Makefile.proto:21: protomk] Error 1这个问题怎么解决
这个错误是由于你的 protobuf 版本过高,而你的生成的代码需要一个较低版本的 protobuf。这个问题有两种可能的解决方案:
- 降级你的 protobuf 包:你可以尝试将你的 protobuf 包降级到 3.20.x 或更低的版本。你可以使用以下命令来降级 protobuf:
pip install protobuf==3.20.0
- 设置环境变量:你可以尝试设置环境变量
PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION
为python
。这将使用纯 Python 解析,但可能会比较慢。你可以使用以下命令来设置环境变量:
export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
如果以上方法都不能解决你的问题,你可能需要使用 protoc
版本 >= 3.19.0 来重新生成你的代码。
这篇关于fix --nanopb_out: protoc-gen-nanopb: Plugin failed with status code 1.的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!