Advertisement

[SOLVED] - AttributeError: module 'collections' has no attribute 'MutableMapping' - DroneKit-Python

January 17, 2022 in Aerospace, Drones by DhulkarnaynDhulkarnayn5 minutes

Embarking on a Python update journey is like giving your digital companion a shiny new upgrade. Recently, I decided to level up my Python version from the trusty 3.9 to the sleek 3.10. With this software glow-up, I eagerly set out to outfit my Python environment with the latest and greatest packages to fuel my programming adventures.

As part of this upgrade extravaganza, I eagerly pip-installed the powerful dronekit library, as expertly guided in our previously shared article. With the installation complete, I even double-checked the success with a trusty terminal command:

pip show dronekit

Behold, the confirmation of a successful dronekit installation, as clear as a GPS signal in the open skies:

Verification of DroneKit-Python Installation

Verification of DroneKit-Python Installation

But, as every adventurer knows, the journey doesn’t truly begin until you take that first step. In Python, that step is the glorious import statement. Picture this: Python 3.10, the stage is set, anticipation in the air, and then, a dramatic twist! An unexpected AttributeError crashes the party, leaving our protagonist dronekit in a perplexing state.

python
Python 3.10.1 (main, Dec 18 2021, 23:53:45) [GCC 11.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import dronekit
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.10/site-packages/dronekit/__init__.py", line 2689, in <module>
    class Parameters(collections.MutableMapping, HasObservers):
AttributeError: module 'collections' has no attribute 'MutableMapping'
>>> 

Unraveling the Pythonic Puzzle: Triumph over the AttributeError!

Ah, the sweet taste of victory in the face of a Pythonic challenge! Our story takes an exhilarating turn as we confront the notorious AttributeError that dared to interrupt our coding symphony. Fear not, for the solution lies within our grasp.

The Quest Begins: Navigating the Dronekit Base

Our hero, the __init.py__ file nestled in the heart of the dronekit base directory, holds the key to our salvation. Picture this file as the ancient map guiding us through the labyrinth of Python packages. The culprit? A line of code, innocently importing MutableMapping from the collections module. Our mission? Upgrade it to dance with the rhythm of Python 3.10.

Python
# Before
from collections import MutableMapping

# After
from collections.abc import MutableMapping

With this swift code tweak, our hero dronekit is now in sync with the latest Python version, ready to soar to new heights!

Community Chronicles: Merging Minds on GitHub

But wait, this tale doesn’t end here. The dronekit realm is alive with a vibrant community, ever watchful for the next challenge. A savior emerges – a noble soul who identified and conquered this very issue. Behold the proof, etched in the sacred GitHub repository in a mighty pull request.

Correct import of MutableMapping for Python 3.10 - Pull Request [Merged]

Correct import of MutableMapping for Python 3.10 - Pull Request [Merged]

This heroic change was etched into the annals of dronekit history in December 2021, a testament to the collaborative spirit of the Python community.

Dronekit - PyPI

Dronekit - PyPI

Note

The Python Package Index (PyPI) is a repository of software for the Python programming language. If you use the pip command to install any python packages, pip retrieves packages from PyPI and installs them.

The Crossroads: Paving Your Path to Glory

Now, fellow adventurers, heed this crucial insight – the treacherous AttributeError may strike when you summon dronekit from the kingdom of PyPI using the sacred pip command:

sudo pip install dronekit

But fear not, for I bring tidings of a safer passage. A path less traveled, yet resilient – install dronekit directly from the source! 🌟

Crafting Your Destiny: Source Installation Ritual

Advertisement

Step 1: Bidding Farewell to Pip’s Proclamation

First, cast away the old with a mighty uninstallation spell, bidding farewell to the dronekit installed by pip:

sudo pip uninstall dronekit

Removing Dronekit - Installed via pip

Removing Dronekit - Installed via pip

Step 2: Clutching the Source Code Scroll

Now, brave coder, seize the dronekit source code from the sacred GitHub repository. A swift git spell shall bring it forth:

git clone https://github.com/dronekit/dronekit-python

Step 3: Enchanting the Installation Ritual

With the source code at your fingertips, navigate to the repository and execute the mystical installation incantation:

sudo python setup.py install
Advertisement

Step 4: Gazing into the Python Crystal Ball

Behold, the installation is complete! Gaze into the Python crystal ball, and in the hallowed lands of the Python environment, try the magical import command:

python

In the mystical realm of Python, conjure the arcane powers with a flourish! Speak forth the enchanting command that beckons the mighty dronekit into your coding sanctuary:

Python
import dronekit

And there it is – a triumphant Python 3.10-compatible dronekit awaits your command!

DroneKit - Python 3.10

DroneKit - Python 3.10

In this grand tale of Pythonic conquest, you’ve not only resolved the AttributeError but emerged victorious with the wisdom to navigate the intricate paths of library installations. Share this saga with your fellow coders, and may your Python adventures be filled with triumph and joy! 🚀💻

Conclusion

In conquering the AttributeError and updating the sacred __init.py__ file, you’ve unleashed the power of dronekit in Python 3.10! 🐉✨ The community’s magic, merged in a GitHub pull request, propels your code into the future.

But your journey continues beyond PyPI’s whispers. Direct installation from the source weaves the freshest spells. Share your triumphs, challenges, and whimsical bug tales in the comments below. Every conclusion sparks a new chapter in the enchanting world of drone programming.


Please consider supporting this project!

If this article has been of help to you, and you feel generous at the moment, don’t hesitate to buy us a coffee. It's an easy, fun and direct way to show your support — any amount of coffee is highly appreciated.
Buy me a Coffee


Comments