Hello, i am new to the world of Robotics, and was working on a simulation using ardupilot and gazebo on the iris drone, for that i needed to use ROS2 with MAVSDK.
Now here’s the problem, ROS2 uses python from usr/bin/python3, while i am unable to pip3 install mavsdk there, as it says its an externally managed environment. (says to see PEP 668 for more details)
apt install would also not work as its a non debian package.
So in my case what it seems like its saying is that i need to install mavsdk in a virtual environment and somehow make ROS2 use that environment for its python needs, but i believe the python that ROS2 will use is determined by colcon build, not by which venv is active in the terminal session.
Therefore i don’t know what to do, is it possible to install MAVSDK in system location, which will allow ROS2 to use it? If true it would save me a lot of time, as i was going to let them run independently (ROS2 using system python and MAVSDK using environment) and then use DDS to communicate with them if no fix was possible.
Generally, I suggest to use ROS 2 or MAVSDK, and not both at the same time, as there is quite some overlap. However, there are cases where you might need both, so that’s fine.
In terms of installing, I assume you need MAVSDK-Python, otherwise you wouldn’t be using pip. In that case, you can either just force it: pip install mavsdk --break-system-packages. Or you can use some py env to make sure the dependencies won’t conflict.
Yes, I need MAVSDK-python, my first thought upon hitting this problem was to have a python venv from where ROS2 will use python and hence MAVSDK will be installed there, but as i have come to find out, ROS2 buils seems to always choose system python over the venv that it’s being run. For more context i am using ROS2 jazzy. I also tried to do some stuff with colcon build, like the following:
```
COLCON_PYTHON_EXECUTABLE=$(which python)
colcon build --symlink-install
Here as i am running in a venv that path should get used(or so i thought)
colcon build
–symlink-install
–cmake-args
-DPython3_EXECUTABLE=$PWD/ros_py/bin/python
Here ros_py is the name of my venv
```
Now both of these methods were suggested to me by chatgpt so i don’t fully understand how they do what i thought they would do, but both didn’t work.
About using pip install mavsdk –break-system-packages`, i just found it a bit risky so didn’t try it yet.
It could work if i do that, but there are chances that it can break some other stuff that can become quite the problem later.
This was my thought process for this, i still haven’t resolved this yet so am still looking forward to discussing more on this.
Hello @JulianOes , I was looking at some other things i could do with the venvs to make it work and i found out i can just add my venvs path to the paths where the system’s python interpreter looks for import packages using: export PYTHONPATH=$VIRTUAL_ENV/lib/python3.12/site-packages:$PYTHONPATH
(Here i was already in my activated virtual env)
After that when i did colcon build and ran my package, it worked.
I was able to have my drone takeoff in the simulation.
Thank you very much, i had given up on venvs and had was looking at Docker containers for this.
I didn’t know such a simple functionality existed.
But Thanks to you talking about venvs, I searched a bit more and was able to solve it.
Hello @David_Patton! No i am not tied to python, its just that i am more comfortable with the language.
And as now i have got it working, i am able to have takeoffs and stuff in gazebo using my python scripts while using ROS2 nodes with it.