compile error -- "no module named nanopb_pb2" occurred when parsing a .proto

3,601 views
Skip to first unread message

yih...@google.com

unread,
Feb 21, 2017, 1:05:23 AM2/21/17
to nanopb
Hi,

I was trying to compile a .proto using the command: protoc --plugin=protoc-gen-nanopb=nanopb/generator/protoc-gen-nanopb, it gives me the following error (I manually installed protobuf3). Any idea what might went wrong?

Traceback (most recent call last):
File "/usr/local/google/home/yihuaz/nanopb/generator/nanopb_generator.py", line 33, in <module>
import proto.nanopb_pb2 as nanopb_pb2
ImportError: No module named nanopb_pb2
--nanopb_out: protoc-gen-nanopb: Plugin failed with status code 1.

Best,
Yihua

Petteri Aimonen

unread,
Feb 21, 2017, 1:32:43 AM2/21/17
to yihuaz via nanopb
Hi,

> ImportError: No module named nanopb_pb2

Try running 'make' in the generator/proto folder.

Usually in this situation it should also show a message that tells you
to do that.

--
Petteri

yih...@google.com

unread,
Feb 21, 2017, 2:17:37 AM2/21/17
to nanopb, j...@kapsi.fi

Thanks Petteri for your quick response. After running make in the generator/proto, I tried to run the protoc command again, and now got the following error

Traceback (most recent call last):

File "/usr/local/google/home/yihuaz/nanopb/generator/nanopb_generator.py", line 21, in <module>
import google.protobuf.text_format as text_format
File "/usr/local/lib/python2.7/dist-packages/protobuf-3.2.0-py2.7.egg/google/__init__.py", line 2, in <module>
File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 3036, in <module>
@_call_aside
File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 3020, in _call_aside
f(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 3064, in _initialize_master_working_set
for dist in working_set
File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 3064, in <genexpr>
for dist in working_set
File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2592, in activate
for pkg in self._get_metadata('namespace_packages.txt'):
File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2582, in _get_metadata
for line in self.get_metadata_lines(name):
File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 1472, in get_metadata_lines
return yield_lines(self.get_metadata(name))
File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 1468, in get_metadata
value = self._get(self._fn(self.egg_info, name))
File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 1577, in _get
with open(path, 'rb') as stream:

IOError: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/protobuf-3.2.0-py2.7.egg/EGG-INFO/namespace_packages.txt'


--nanopb_out: protoc-gen-nanopb: Plugin failed with status code 1.

Do you have an idea on this?

Petteri Aimonen

unread,
Feb 21, 2017, 5:52:57 AM2/21/17
to yihuaz via nanopb
Hi,

> IOError: [Errno 13] Permission denied:
> '/usr/local/lib/python2.7/dist-packages/protobuf-3.2.0-py2.7.egg/EGG-INFO/namespace_packages.txt'

This seems like a broken protobuf installation on your computer.

Does running this command give any errors?
python -c 'import google.protobuf.text_format'

If it does, it means your protobuf installation is not working properly.
I haven't seen that error before so I don't know in what particular way
it is broken.

(btw, if you want an easier start, the binary packages work without
installing protobuf 3 separately.)

--
Petteri

Yihua Zhang

unread,
Feb 21, 2017, 12:24:16 PM2/21/17
to nan...@googlegroups.com
Hi Petteri,

I just re-installed python-protobuf (no errors emitted during the installation), and re-ran the command, and now it gives me the error: ImportError: No module named google.protobuf.text_format. 
The reason I was trying to use the source version (instead of binary) is that when using the binary version to compile my proto, it seems not support the callbacks fields inside oneof by prompting an exception. So, I would like to compile the nanopb with protobuf 3, and see if it supports the feature. On the other hand, do you know how to let nanopb to support the aforementioned feature? 

Thanks in advance. 
Yihua




--
You received this message because you are subscribed to a topic in the Google Groups "nanopb" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nanopb/SVGAvxsJsrw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nanopb+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Petteri Aimonen

unread,
Feb 21, 2017, 2:30:51 PM2/21/17
to 'Yihua Zhang' via nanopb
Hi,

> On the other hand, do you know how to let nanopb to support the
> aforementioned feature?

Currently it is not possible to use callbacks inside oneof. You can
either use non-callback fields, or set no_unions=true so that the oneof
is generated like separate optional fields.

See here for more information:
https://github.com/nanopb/nanopb/issues/210

--
Petteri

Yihua Zhang

unread,
Feb 21, 2017, 3:33:25 PM2/21/17
to nan...@googlegroups.com
Thanks a lot, the problem is resolved after setting no_unions=true. I am also surprised to see nanopb can parse "map" data types used in my proto file.


--
Petteri

Reply all
Reply to author
Forward
0 new messages