Home        Store        Learn        Blog

Problem building application with pyinstaller and pymavlink

I am trying to convert a python file into an executable using pyinstaller. The issue is I can’t get a python file which uses the pymavlink library to run as an executable. I am running python 2.7.17 in Ubuntu 18.04. Pymavlink 2.4.14 and Pyinstaller 3.5

Heres an example file:

# imports
from pymavlink import mavutil

# CONNECT
master = mavutil.mavlink_connection('udpin:0.0.0.0:14777')

# WAIT FOR HEARTBEAT BEFORE SENDING ANY COMMANDS 
master.wait_heartbeat()

# CHANGE TO FLIGHT MODE DEPTH HOLD MODE
master.mav.set_mode_send(
     master.target_system,
     mavutil.mavlink.MAV_MODE_FLAG_CUSTOM_MODE_ENABLED,
     2)

#addition to build file into single application with pyinstaller
if 0:
     import UserList
     import UserString
     import UserDict
     import itertools
     import collections
     import future.backports.misc
     import commands
     import base64
     import __buildin__
     import math
     import reprlib
     import functools
     import re
     import subprocess

The additional imports are explicitly added as a solution for libraries that are getting skipped.

The error is as follows:
pymavlink_issue


I edited the spec file to try and circumvent this but haven’t found a solution. Attempting to add the path manually changes the error to

ImportError: No module named v20.ardupilotmega
[18806] Failed to execute script rov

If anyone knows a way around this I’d greatly appreciate it

Hi @plano,

I would recommend to use a newer version of python if possible, Python 2.7 has reached end of life.
Maybe you can have more luck with pipenv or any environment variable for python, pyinstaller can be a bit tricky.

Hi Patrick,

I have tried newer versions of python but I haven’t had any luck installing pymavlink following the instructions online for python 3. Usual issue is it fails with an error building the wheel. Have tried changing the version of pip, pymavlink etc. I’ve been working with virtualenv for different versions.

I have managed to build my application on windows with anaconda but am not 100% sure if the pymavlink part is working as I haven’t access to a physical ROV at the moment and only have SITL running on Linux or WSL. Also trying to run this application on Linux with wine hasn’t worked due to partition confusions and as the actual file I want run is a tkinter application, generally running gui style applications through wine not being the most straightforward.

Removing the pymavlink functions I can load the tkinter GUI as an application fine on windows and Linux, so the above test script is to try and isolate it to a simple example

Ben

An update to that, I managed to get the application built with python 3.6.7. However the same error “no file or directory” issue, is seen.

If anyone knows of a way of explicitly adding the pymavlink library to the spec file I’d greatly appreciate it as it isn’t linking itself correctly, automatically.

Hi @plavo,

I would recommend to create a minimal example and ask for guidance on the pymavlink repository directly: GitHub - ArduPilot/pymavlink: python MAVLink interface and utilities
They will be able to help you more with this specific task.

1 Like