Could anyone please share a current link on the successful use of running an ROS2 node (>= Humble) in a venv with a different python version?
The troubles ...
My ROS2 system is on an RPi and Ubuntu 22.04 installed with the arm64 raspy image. Ubuntu's system python version is 3.10.
I need to create an ROS2 package for a Coral device which uses pycoral, which requires python <=3.9. Ubuntu 22.04 uses python3.10.
To test this I'm using the base Ubuntu install and only adding python3.9 through apt-get.
I installed ROS2 Humble using the Debian packages (not from source).
I installed the simple published example from https://docs.ros.org/en/humble/Tutorials/Beginner-Client-Libraries/Writing-A-Simple-Py-Publisher-And-Subscriber.html and that builds and runs fine.
I then added "import pycoral" to the publisher_member_function.py, built it, sourced the install dir and ran it and as expected the module could not be imported.
I then created a venv named venv-3.9.2
python3.9 -m venv venv-3.9.2 --system-site-packages --symlinks
Note - I also tried this without the extras:
python3.9 -m venv venv-3.9.1
Then activated that and added pycoral using python -m pip install pycoral. I ran a test.py with import pycoral and the import succeeded.
Still in the venv, I ran the talker
ros2 run py_pubsub talker
Again, the pycoral module could not be found, but the log indicates the script is looking in /usr/lib/python3.10.
I also tried adding this to setup.cfg and rebuilding:
executable = /home/mark/venv-3.9.2/bin/python
Running this after build creates an error including:
ModuleNotFoundError: No module named 'rclpy._rclpy_pybind11'
I also tried the order of building and activating the venv and installing colcon in the venv per https://github.com/ros2/ros2/issues/1094 - still no luck.
This seems to be a common issue but I can't find a clear example on how to successfully do this.