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 first set up update-alternativesneed to install Python3create an ROS2 package for a Coral device which uses pycoral, which requires python <=3.9 and set that as. Ubuntu 22.04 uses python3.10.
To test this I'm using the version displayedbase Ubuntu install and only adding python3.9 through apt-get.
I installed ROS2 Humble using pythonthe Debian packages (not python3from 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 --pythonm version
Pythonvenv venv-3.9.18
$2 python3--system-site-packages --versionsymlinks
Python
Note - I also tried this without the extras:
python3.9 -m venv venv-3.109.121
I installed ROS2 Humble in ~ from source per https://docs.ros.org/en/humble/Installation/Alternatives/Ubuntu-Development-Setup.html
The resulting build is in ~/ros2_humble. All packagesThen activated that and added pycoral using python were built to include Python3-m pip install pycoral.10 I ran a test.py with import pycoral and the import succeeded.
I also need to use opencv and cv_bridge from vision_opencv but when I build thatStill in the venv, it also includes Python3.10.I ran the talker
ros2 run py_pubsub talker
I have an object detection node that needs to useAgain, the pycoral and other libraries which require Python3.9. After strugglingmodule could not be found, but the log indicates the script is looking in - Python 3/usr/lib/python3.10 will not work with these packages.
I can build the node using colcon build --packages-select <my_node> and that build includes Python3.9also tried adding this to setup.cfg and rebuilding:
[build_scripts]
executable = /home/mark/venv-3.9.2/bin/python
After sourcing install, when I run my node it errors outRunning this after build creates an error including:
ModuleNotFoundError: No module named 'rclpy._rclpy_pybind11'
I also tried setting up a venv using python3.9 andthe order of building and activating the humble sourcevenv and installing colcon in thatthe venv per https://github.com/ros2/ros2/issues/1094 - but still building humble from source uses the system python 3.10no luck.
How can I buildThis seems to be a node that usescommon issue but I can't find a python package that dependsclear example on python3how to successfully do this.9 in an ROS2 Humble install?