You are not allowed to have a file named "parrot.py" in the execution directory

Nice bug (?), stumbled upon this.

pi@raspberrypi:~ $ source /home/pi/code/parrot-groundsdk/products/olympe/linux/env/shell 
(olympe-python3) pi@raspberrypi:~ $ mkdir test
(olympe-python3) pi@raspberrypi:~ $ cd test
(olympe-python3) pi@raspberrypi:~ $ python
Python 3.9.5 (default, Jun 20 2022, 17:45:45) 
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import olympe
>>> 

All fine.

But now it comes:

(olympe-python3) pi@raspberrypi:~/test $ 
(olympe-python3) pi@raspberrypi:~/test $ touch parrot.py
(olympe-python3) pi@raspberrypi:~/test $ python
Python 3.9.5 (default, Jun 20 2022, 17:45:45) 
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import olympe
ModuleLoader unhandled exception
Traceback (most recent call last):
  File "/home/pi/code/parrot-groundsdk/out/olympe-linux/staging/usr/lib/python/site-packages/olympe/module_loader.py", line 74, in add_package_root
    self.enums[root] = ArsdkEnums.get(root)
  File "/home/pi/code/parrot-groundsdk/out/olympe-linux/staging/usr/lib/python/site-packages/olympe/arsdkng/enums.py", line 438, in get
    ret = ArsdkEnums(root)
  File "/home/pi/code/parrot-groundsdk/out/olympe-linux/staging/usr/lib/python/site-packages/olympe/arsdkng/enums.py", line 448, in __init__
    self._proto = ArsdkProto.get(root)
  File "/home/pi/code/parrot-groundsdk/out/olympe-linux/staging/usr/lib/python/site-packages/olympe/arsdkng/proto.py", line 201, in get
    ret = ArsdkProto(root)
  File "/home/pi/code/parrot-groundsdk/out/olympe-linux/staging/usr/lib/python/site-packages/olympe/arsdkng/proto.py", line 257, in __init__
    self.parse_protos()
  File "/home/pi/code/parrot-groundsdk/out/olympe-linux/staging/usr/lib/python/site-packages/olympe/arsdkng/proto.py", line 542, in parse_protos
    _, feature = self.parse_proto(
  File "/home/pi/code/parrot-groundsdk/out/olympe-linux/staging/usr/lib/python/site-packages/olympe/arsdkng/proto.py", line 633, in parse_proto
    spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 855, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/tmp/tmps2knu8de/arsdk/microhard_pb2.py", line 17, in <module>
ModuleNotFoundError: No module named 'parrot.protobuf'; 'parrot' is not a package
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/pi/code/parrot-groundsdk/out/olympe-linux/staging/usr/lib/python/site-packages/olympe/__init__.py", line 32, in <module>
    from .controller import Drone, SkyController
  File "/home/pi/code/parrot-groundsdk/out/olympe-linux/staging/usr/lib/python/site-packages/olympe/controller.py", line 32, in <module>
    from .arsdkng.cmd_itf import Connect, Disconnect, Connected, Disconnected  # noqa
  File "/home/pi/code/parrot-groundsdk/out/olympe-linux/staging/usr/lib/python/site-packages/olympe/arsdkng/cmd_itf.py", line 42, in <module>
    from olympe.enums import drone_manager as drone_manager_enums
ImportError: cannot import name 'drone_manager' from 'olympe.enums' (/home/pi/code/parrot-groundsdk/out/olympe-linux/staging/usr/lib/python/site-packages/olympe/enums/__init__.py)
>>> 

:slight_smile:

Hi,

This has nothing to do with Olympe, here is a an example of polluting the Python path with an empty “json” module.

$ echo {} | python3 -m json.tool
{}
$ touch json.py
$ echo {} | python3 -m json.tool
/usr/bin/python3: Error while finding module specification for 'json.tool' (ModuleNotFoundError: __path__ attribute not found on 'json' while trying to find 'json.tool
$ rm json.py

I came across this because I had a valid “parrot.py” file in the local directory. I renamed it and it worked.

Please double check. It seems to be a protocol buffer issue (as the message suggests)

You can add a “print(‘Hello’)” to the “parrot.py”, you will run into the same error.

I’m also not sure, what your sample is supposed to prove. You can have an empty “test.py” instead of “parrot.py” and the import works fine.

It is a matter of the name of the python file and it has to do with the way protocol buffer is used as it seems from the error.

But feel free to ignore. I have renamed the file and it works for me.

Again, it’s not a protocol buffer error nor a bug in Olympe.
The problem was you were masking the package “parrot.protobuf” (that just happen to be imported by Olympe at some point) with your file “parrot.py” in your current working directory (which is always appended to the sys.path/"PYTHONPATH).

ModuleNotFoundError: No module named 'parrot.protobuf'; 'parrot' is not a package

The error message just tells you that the Python interpreter found a module named “parrot” but since it is not a package (it’s just a regular module: parrot.py), the interpreter can’t import a subpackage “parrot.protobuf” from it.

Well, ok. But why?

However, I don’t see my initial claim proven wrong. You can’t have a python module named “parrot.py”.

Not sure, why your are not seeking for “parrot.protobuf” explicitly, but that’s your turn.

I’m done with this.

BTW: The 32 bit version does not have a problem with this. One indication more, that there is a hidden problem with protobuf if compiled 32 bit (we talked about, your explanation made sense). I’m having tons of “unknown messages” in 32 bit, which I don’t have in 64 bit.

But this is also not a problem anymore.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.