python 2.7 - attempted relative import in non-package error in mavlink

I've already looked through the forums, but I haven't found an answer that is mavlink specific.

I am currently writing script in python, and I want to use a python module of mavlink. The documentation for mavlink tells me to run mavgenerate.py from my mavlink folder. When I run this script, a gui appears asking for my xml files, a specified output directory, and what language I want my headers in. mavgenerate.py works when I choose to make headers for C, but it gives me the error: "attempted relative import in non-package" when I try to choose python. my xml files is located at:

C:\Python27\mavlink\message_definitions\v1.0

and I have my python module output directory as:

C:\Python27\mavlink\pymavlink\include

below is a screenshot of my error.

screenshot

can anyone tell me what I'm doing wrong?

1 Answer

  1. Leo- Reply

    2019-11-16

    This is quite an old question but i have just encountered with this problem. Solution that i have applied is: in mavgenerate.py replace following lines

    sys.path.append(os.path.join('pymavlink','generator'))
    from mavgen import *
    

    with

    from pymavlink.generator.mavgen import *
    

    I dont know the exact reason of the problem but from this thread i assume problem lies with python's interpretation of directories as packages.

    I have used python 2.7. Tried though to do with python 3.4 but didn't had chance there.

Leave a Reply

Your email address will not be published. Required fields are marked *

You can use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>