I’ve recently updated the base version of Python in my device from 3.9
to 3.10
version. After updating the base version, I started installing all the required python packages for my workflow. Likewise, I installed dronekit
using pip
, as mentioned in the linked article.
Also, after installing the dronekit
, I’ve verified the installation using the following pip
command on the terminal:
1
$ pip show dronekit
The output of the above command is:
Verification of DroneKit-Python Installation
But, when I tried to import
the dronekit
package on python, I’ve encountered the following AttributeError
.
1
2
3
4
5
6
7
8
9
10
$ 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'
>>>
How to resolve this issue?
This issue can be easily fixed by updating the __init.py__
file present in the dronekit
base directory. The from collections import MutableMapping
needs to be updated as from collections.abc import MutableMapping
, making the package compatible with Python 3.10
.
Since dronekit
has active community support, this issue was already identified and merged into the main
branch of the dronekit-python GitHub repository.
Correct import of MutableMapping for Python 3.10 - Pull Request [Merged]
This change was merged recently on December 2021 in the main
repository, and the last updated version in PyPI is dronekit 2.9.2
, dated 18 March 2019.
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 install them.
Since I’ve installed dronekit
on my device using the following command on the terminal, the AttributeError
occurred on my device. The reason for the error is that the recent merge is not included in PyPI.
1
$ sudo pip install dronekit
Instead of installing the dronekit
via pip
, installing directly from the source will avoid this issue! ✨
Advertisement
Installing DroneKit - Directly from the Source
Removing DroneKit - Installed via pip
Firstly, remove the previously installed dronekit
package because that was installed using pip
. Execute the following command on your terminal to remove dronekit
from your device:
1
$ sudo pip uninstall dronekit
Removing Dronekit - Installed via pip
Note
You can verify the status of the removal of
dronekit
by executing the following command on your terminal:
1 $ pip show dronekit
Cloning DroneKit
After the successful removal of the dronekit
, you can directly download (clone) the dronekit GitHub repository to your device by executing the following git
command on your terminal:
1
$ git clone https://github.com/dronekit/dronekit-python
Note
If
git
is not already installed on your device means, execute the following command on your terminal to installgit
:
1 2 $ sudo apt-get update $ sudo apt-get install git
Installing DroneKit
After cloning the dronekit repository, open the terminal from that folder and execute the following command on that terminal to directly install dronekit
from the source:
1
$ sudo python setup.py install
Advertisement
Verifying Installation
Now, you can verify the installation by directly importing the dronekit package on the python environment. For opening python environment on your device, execute the following command on your device:
1
$ python
In python environment, try executing the following command to import the dronekit
:
1
import dronekit
The following image is the output for the execution of the above command:
DroneKit - Python 3.10
Tada, you’ve successfully installed DroneKit-Python on Python 3.10!!! ✨
Conclusion
In this article, I’ve tried to explain how to resolve AttributeError
while importing dronekit
on python version 3.10
. I’m expectantly waiting for your valuable feedback and suggestions regarding this topic.
At last, Sharing is Caring, feel free to share with your friends if you’ve liked this article. Thank you!
Comments
You didnt said in wchich folder should be run command “ sudo python setup.py install”
“After cloning the dronekit repository, open the terminal from —- THAT —-folder and execute the following command on that terminal to directly install dronekit from the source:”
WHAT? :)
Oh, I meant the cloned DroneKit repository folder/directory.
I’m pleased you found this article helpful.