Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
added 626 characters in body; edited title
Source Link

Using Python3.9 libraries Can an ROS2 node run in a node on Ubuntu 22.04/ROS2 Humblevenv and use a different python than that used by the ROS2 installed version?

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?

Using Python3.9 libraries in a node on Ubuntu 22.04/ROS2 Humble

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-alternatives to install Python3.9 and set that as the version displayed using python (not python3).

$ --python version
Python 3.9.18
$ python3 --version
Python 3.10.12

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 packages using python were built to include Python3.10.

I also need to use opencv and cv_bridge from vision_opencv but when I build that, it also includes Python3.10.

I have an object detection node that needs to use pycoral and other libraries which require Python3.9. After struggling - Python 3.10 will not work with these packages.

I can build the node using colcon build --packages-select <my_node> and that build includes Python3.9.

After sourcing install, when I run my node it errors out including:

ModuleNotFoundError: No module named 'rclpy._rclpy_pybind11'

I tried setting up a venv using python3.9 and building the humble source in that venv - but still building humble from source uses the system python 3.10.

How can I build a node that uses a python package that depends on python3.9 in an ROS2 Humble install?

Can an ROS2 node run in a venv and use a different python than that used by the ROS2 installed version?

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:

[build_scripts]
 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.

Source Link

Using Python3.9 libraries in a node on Ubuntu 22.04/ROS2 Humble

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-alternatives to install Python3.9 and set that as the version displayed using python (not python3).

$ --python version
Python 3.9.18
$ python3 --version
Python 3.10.12

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 packages using python were built to include Python3.10.

I also need to use opencv and cv_bridge from vision_opencv but when I build that, it also includes Python3.10.

I have an object detection node that needs to use pycoral and other libraries which require Python3.9. After struggling - Python 3.10 will not work with these packages.

I can build the node using colcon build --packages-select <my_node> and that build includes Python3.9.

After sourcing install, when I run my node it errors out including:

ModuleNotFoundError: No module named 'rclpy._rclpy_pybind11'

I tried setting up a venv using python3.9 and building the humble source in that venv - but still building humble from source uses the system python 3.10.

How can I build a node that uses a python package that depends on python3.9 in an ROS2 Humble install?