Softivation

DroneKit won't install (Python 3.11 and above)

pip install dronekit succeeds but import dronekit crashes. What causes it on Python 3.11 and above, which install path works, and takeoff code with pymavlink.

Furkan IŞIKAY 8 min read

You install DroneKit with pip and the install finishes without problems. Then you import DroneKit on the first line of your code, and the program stops right there.

This is one of the places that burns the most time in competition prep. There's nothing wrong in your code, and you didn't install it incompletely. The problem is in the package itself, and it has been there for years.

Below you'll see where each install path stands on Python 3.11.15, with the exact error text.

Why pip succeeds but import crashes

pip's job is to download the package and put it in place. It doesn't check whether the package will work on that Python version. For that, the package's own metadata has to say "I work on these versions."

That line is empty in DroneKit's metadata. The latest version on PyPI is 2.9.2, uploaded on March 18, 2019. Python 3.10 came out two and a half years after that. So the published package has never seen the Python you're using.

In Python 3.10, something moved inside the language: the definitions of dictionary-like classes moved from collections to collections.abc. DroneKit still uses the old address, and that address no longer exists.

The most common advice on the forum doesn't work today

The first suggestion that comes up when you search for this error is: "Drop the PyPI version and install straight from the GitHub repo, it's fixed there."

Half of the fix really is there. The current code in the repo uses the correct address for Python 3.10 and above. But on line 51 of the package's main file (dronekit/__init__.py), it calls another library that isn't named anywhere in the install list. When you install from the repo, that library doesn't come along, and this time the import stops earlier.

So there's no one-line fix. If you want to keep DroneKit alive, you have to add the missing library by hand. With the PyPI version, you also have to fix the moved address from inside your code.

Where each install path stands

Putting the five paths side by side gives this table. The first three rows end up in the same place: the install looks successful, and it ends at the import line.

Install pathResultWhat you see on screen
pip install dronekitimport crashesModuleNotFoundError: No module named 'past'
pip install dronekit futureimport still crashesAttributeError: module 'collections' has no attribute 'MutableMapping'
pip install git+.../dronekit-python.git (master branch, the most recommended on forums)import crashesModuleNotFoundError: No module named 'past'
git version + future, or pip + future + shimimport worksTwo extra steps are needed; the package hasn't been updated since 2019.
pip install pymavlink (2.4.49, August 1, 2025)import worksNo extra steps, and the package is actively maintained.

There are two paths, and both work

The first is keeping DroneKit alive: install the missing library and, if needed, wire up the moved address by hand before the import. For running an old project you already have, this path makes sense. DroneKit works in a Python 2.7 environment without needing these fixes. That's why our Python course uses that environment.

The second, if you're starting a brand-new project on Python 3.10 or above, is to use pymavlink directly instead of DroneKit. pymavlink is already running underneath DroneKit. When you use it directly, the layer in between disappears, and the same takeoff job takes this much code:

Python
import time
from pymavlink import mavutil

HEDEF_IRTIFA = 10.0
m = mavutil.mavlink_connection('tcp:127.0.0.1:5760', source_system=255)
m.wait_heartbeat(timeout=60)

# Without this line GPS_RAW_INT never arrives and the loop waits forever
m.mav.request_data_stream_send(m.target_system, m.target_component,
                               mavutil.mavlink.MAV_DATA_STREAM_ALL, 4, 1)
time.sleep(1)

# No ARM permission until a 3D fix and at least 6 satellites
while True:
    msg = m.recv_match(type='GPS_RAW_INT', blocking=True, timeout=5)
    if msg and msg.fix_type >= 3 and msg.satellites_visible >= 6:
        print('GPS 3D fix, %d sats' % msg.satellites_visible)
        break
time.sleep(8)

m.mav.set_mode_send(m.target_system,
    mavutil.mavlink.MAV_MODE_FLAG_CUSTOM_MODE_ENABLED, m.mode_mapping()['GUIDED'])
time.sleep(2)

# ARM may be rejected on the first try: the prearm chain may not have passed yet
for i in range(20):
    m.mav.command_long_send(m.target_system, m.target_component,
        mavutil.mavlink.MAV_CMD_COMPONENT_ARM_DISARM, 0, 1, 0, 0, 0, 0, 0, 0)
    ack = m.recv_match(type='COMMAND_ACK', blocking=True, timeout=3)
    if ack and ack.result == 0:
        print('ARMED (attempt %d)' % (i + 1))
        break
    time.sleep(2)

m.mav.command_long_send(m.target_system, m.target_component,
    mavutil.mavlink.MAV_CMD_NAV_TAKEOFF, 0, 0, 0, 0, 0, 0, 0, HEDEF_IRTIFA)

# ACK means "command accepted"; confirm the altitude separately
while True:
    p = m.recv_match(type='GLOBAL_POSITION_INT', blocking=True, timeout=5)
    if p and p.relative_alt / 1000.0 >= HEDEF_IRTIFA * 0.95:
        print('altitude: %.2f m' % (p.relative_alt / 1000.0))
        break

This code runs on its own, the install is one line, and there's no outdated package in between. If you connect to ArduCopter 4.7.0 and run it, you'll see this in the terminal:

Output
GPS 3D fix, 10 sats
ARMED (attempt 1)
altitude: 9.70 m

In the field, it can take time for GPS to get a fix and for the satellite count to rise. Wind and vibration also change how the takeoff looks. This output shows that the code's flow advances in the right order.

Two traps

If you don't request the telemetry stream, the GPS message never arrives. The code gets stuck forever in the loop that waits for GPS, and you think the code has locked up. Most examples don't have that line.

The second is sneakier: the acknowledgment that comes back for the TAKEOFF command says the command was accepted, not that the target was reached. If you see the ack and move on to the next command, the mission sequence breaks. You have to confirm the altitude separately.

In the figure, the dashed vertical line is the moment the command goes out. About five seconds pass until the red dot where the altitude loop exits. The drone settles at 10 meters without overshoot.

Altitude reaching the target after TAKEOFF

The TAKEOFF command goes out at 3.75 seconds. Altitude passes 95 percent of the target at 8.75 seconds, at 9.70 meters, and settles at 10 meters without overshoot.
Where to look: between the dashed vertical line and the red dot. At the moment the command goes out, the drone is still on the ground. Without an altitude loop, these five seconds don't show up in your code.

Example: In a payload drop mission, if your code sends the command to go to the first waypoint as soon as it sees the TAKEOFF ack, the new command arrives while the drone is still at the start of the curve in the figure, and the mission sequence breaks. First wait for the altitude loop to pass 95 percent of the target, and send the waypoint command only after that.

Error Messages and Their Meanings

The messages you can see on screen from install to takeoff, and what they mean.

ModuleNotFoundError: No module named 'past'

A helper library DroneKit needs didn't come along because the package's install list doesn't mention it. You have to install it by hand. You see this error both with the PyPI version and when installing from the GitHub repo.

AttributeError: module 'collections' has no attribute 'MutableMapping'

The trace of the address that moved in Python 3.10. Specific to PyPI version 2.9.2; it shows up at line 2689 of the file. In the current code on GitHub, this line is fixed.

PreArm: GPS 1: Bad fix

The autopilot won't allow ARM because the GPS hasn't produced a 3D position solution yet. If your code repeats the ARM attempt, this message repeats a few times. There's nothing to do except wait.

PreArm: High GPS HDOP

There's a fix but the satellite geometry is weak. The autopilot is saying the position isn't precise enough. Move to an open area; when the satellite count rises, this message goes away.

PreArm: Need Position Estimate

The flight mode you chose needs position information, but the autopilot hasn't been able to form a reliable position estimate yet. GUIDED is one of these modes. You can't switch to GUIDED until the position estimate settles.

PreArm: AHRS: waiting for home

The autopilot hasn't recorded the takeoff point yet. ARM isn't allowed until the home point settles. This also depends on the position solution settling.

If you see result 4 in COMMAND_ACK: this value means "the command was executed but failed." If you're seeing it on the ARM command, the cause is one of the pre-arm checks. The real cause arrives as a separate text message. If your code only looks at the ack code, you never see the cause.

Resources

Latest version of the package and its upload date: PyPI · dronekit

ArduPilot's list of companion computer software: ArduPilot · Companion Computers

A forum thread asking the same question: ArduPilot Discourse · High Level Python API for operations

For readers of this article

The code here gets the takeoff done. But mission upload, the difference between GUIDED and AUTO, control from a companion computer and the vehicle class's attributes each need a separate sequence. In the course they proceed week by week, hands-on.

See the course: Drone Control with Python from Scratch

Was this article helpful?

Free resourcePixhawk and ArduPilot error message glossaryThe 4 messages in this article and similar ones are in the glossary: what they mean, why they appear, what to check first.