ImportError in example/simple issue on Ubuntu 20.04

999 views
Skip to first unread message

Constantine Shulyupin

unread,
May 10, 2021, 8:19:52 AM5/10/21
to nanopb

examples/simple$ \make
../../generator/protoc  --nanopb_out=. simple.proto
Traceback (most recent call last):
  File "/home/costa/oss/nanopb/generator/nanopb_generator.py", line 51, in <module>
    from .proto import nanopb_pb2
ImportError: attempted relative import with no known parent package

Petteri Aimonen

unread,
May 10, 2021, 8:29:00 AM5/10/21
to nan...@googlegroups.com
Hi,

Is that the whole error message?
It should have a try-except to try importing without the relative path.

Does nanopb_pb2.py appear in generator/proto directory?
If not, can you try running "make -C generator/proto"

If that still doesn't help, what happens if you run
generator/nanopb_generator.py directly?
It should print help message if it starts ok.

I don't get that error message on Ubuntu 20.04 for some reason.

--
Petteri

Constantine Shulyupin

unread,
May 10, 2021, 9:20:08 AM5/10/21
to nan...@googlegroups.com
costa@costa-hp:~/.../examples/simple$ ls -l ../../generator/proto/
total 52
drwxrwxr-x 3 costa costa 4096 Apr 25 10:26 google
-rw-rw-r-- 1 costa costa 1127 Apr 25 10:26 __init__.py
-rw-rw-r-- 1 costa costa 83 Apr 25 10:26 Makefile
-rw-rw-r-- 1 costa costa 21906 May 10 15:17 nanopb_pb2.py
-rw-rw-r-- 1 costa costa 6611 Apr 25 10:26 nanopb.proto
drwxrwxr-x 2 costa costa 4096 May 10 15:18 __pycache__
-rw-rw-r-- 1 costa costa 1124 Apr 25 10:26 _utils.py
costa@costa-hp:~/.../examples/simple$ ../../generator/nanopb_generator.py
Traceback (most recent call last):
File "../../generator/nanopb_generator.py", line 51, in <module>
from .proto import nanopb_pb2
ImportError: attempted relative import with no known parent package

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "../../generator/nanopb_generator.py", line 72, in <module>
import proto.nanopb_pb2 as nanopb_pb2
File "/home/costa/oss/nanopb/generator/proto/nanopb_pb2.py", line 10,
in <module>
from google.protobuf import symbol_database as _symbol_database
ImportError: cannot import name 'symbol_database' from
'google.protobuf'
(/usr/local/lib/python3.8/dist-packages/google/protobuf/__init__.py)
> --
> You received this message because you are subscribed to the Google Groups "nanopb" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to nanopb+un...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/nanopb/20210510122858.GA9947%40lakka.kapsi.fi.



--
Constantine Shulyupin

Petteri Aimonen

unread,
May 10, 2021, 11:07:09 AM5/10/21
to nan...@googlegroups.com
Hi,

> During handling of the above exception, another exception occurred:
>
> Traceback (most recent call last):
> File "../../generator/nanopb_generator.py", line 72, in <module>
> import proto.nanopb_pb2 as nanopb_pb2
> File "/home/costa/oss/nanopb/generator/proto/nanopb_pb2.py", line 10,
> in <module>
> from google.protobuf import symbol_database as _symbol_database
> ImportError: cannot import name 'symbol_database' from
> 'google.protobuf'
> (/usr/local/lib/python3.8/dist-packages/google/protobuf/__init__.py)

This sounds like the installed protoc version on the system is
incompatible with the installed python-protobuf version.

It may be possible to solve this using:

pip install grpcio-tools protobuf

which installs both of them from Python package manager so they should
be matching versions.

--
Petteri

Martin Holtan

unread,
Dec 16, 2021, 4:07:51 AM12/16/21
to nanopb

`pip install --upgrade protobuf`

Did the trick for me.
-martin

Benjen Greyjoy

unread,
Sep 22, 2022, 2:53:09 PM9/22/22
to nanopb
you can also try: 
pip install --upgrade grpcio-tools

Ajay

Reply all
Reply to author
Forward
0 new messages