Using Shebang in ROS2

asked 2022-09-25 21:04:31 -0500 gravatar image

Hi everyone! I used to be a ROS1 user, but recently I switched to ROS2 foxy. I couldn't use Shebang to change the python environment for running my node (Same as what I used to do in ROS1).

Here is the sample shebang code:

import cv2
def main():
    print('Hi from test2.')

After running this, still it will be run by default ros python env.

FYI, I have created the package by Colcon.

Anyone know how I could address this issue?

edit retag flag offensive close merge delete


I believe your objective is to run ROS 2 inside virtualenv. If yes, please see the following link: #q371083

ravijoshi gravatar image ravijoshi  ( 2022-10-03 02:37:35 -0500 )edit

Thanks. I was trying to run different nodes with different virtual environment. The solution I found was using launch file with 'launch-prefix' argument. gravatar image  ( 2023-03-14 02:53:37 -0500 )edit