Snapcraft and venv clash
Posted on
Although this is not about C++, the following seemed interesting enough to me to have it published.
Walking through the example projects of the excellent Webots robotics simulation platform, I encountered a puzzling problem which took me a few days to solve. I taught I would share the solution here to help out anybody losing his mind over this! My problem was with the ABB IRB simulation. I could not get it to run on my computer because the ikpy Python module was not found. Of course I already had ikpy installed in a virtual environment (As this is a good practice whenever working with Python). I used venv for that purpose. And I was running Webots in the context of that virtual environment. But I figured that the system Python interpreter was called at runtime, instead of the one from my venv. Which logically lead to that "ikpy module not found" error.
I investigated this by tracking down the PATH environment variable in the few processes launched by Webots. By the way, my workstation runs on Kubuntu. So I mainly achieved this by making use of:
ps -e --forest -o pid,comm,exe,args
This is to list processes and the path to their executable.
And:
xargs -0 -L1 -a /proc/pid/environ | grep PATH
To check what PATH environment variable is visible to the pid process.
The thing that struck me is that there was no trace of venv in the PATH variable of webots, even though webots was directly run from venv! The PATH visible to webots only contained Snapcraft entries, like the following:
$SNAP/usr/sbin:$SNAP/usr/bin:$SNAP/sbin:...
It occured to me that Snapcraft was overwriting the PATH, with no consideration whatsoever for venv entries! This is in fact not a bug, but a feature, as documented here.
Long story short, I could find no way of really fixing this... It seems that Snapcraft and venv are just not meant for each other!
So I had to give up on one of them: Either install the Python ikpy module system-wide, or quit using the Snap package of Webots. The latter seemed less painful to me. So I settled on using the APT package of Webots. And guess what? The ABB simulation now works like a charm!