ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Hi!

To run the nodes in a virtual environment of your choice, you should change the shebang (i.e. the very first line in your script which should look something like #!/usr/bin/env python) of your scripts so to point to the Python interpreter of the virtual environment.

As an example, if your virtual environment name is venv the first line in the script should be #!/path/to/venv/bin/python3. This is of course not so portable, as you are hardcoding the path in each and every script. A more flexible solution I have recently started to use is to set the virtual environment from the launch file with

 <arg name="venv" value="/path/to/venv/bin/python3" />
 <node> pkg="pkg" type="node.py" name="node" launch-prefix = "$(arg venv)" />

so if you migrate the venv, you just have to adapt the path to the interpreter in one place (i.e. the launch file).

As for the

ModuleNotFoundError: No module named "rospkg"

you should be able to solve by simply activating your virtual environment and installing rospkg into it with pip install rospkg.