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

ros2 run- Cannot find 'rclpy', but python node.py finds it

asked 2019-10-10 18:00:39 -0500

sansoucie gravatar image

I am attempting to run a python node in ROS2 Dashing, but ros2 run is unable to find rclpy. Running the node's script with "python3.6 node.py" works fine, however. I've included a minimal example (minimalpkg/minimal.py) that triggers the warning after building and attempting to run with the following commands from the base directory of the workspace:

colcon build
source install/setup.bash
ros2 run minimalpkg minimal

However, the node runs fine with no errors when I use the python interpreter:

python3.6 minimal.py

Names and versions of stacks/packages that you're using: ROS2 Dashing, Python 3.6

Your platform (architecture, OS & version/distro): Ubuntu 18.04.3 (bionic) LTS

minimal.py: `

#!/usr/bin/python3.6
import rclpy
from rclpy.node import Node
from std_msgs.msg import String
import numpy as np


class TestNode(Node):
    def __init__(self):
        super().__init__("test_node")
        self.subscription = self.create_subscription(
            String, "messages", self.listener_callback, 10
        )

    def listener_callback(self, msg: String):
        self.get_logger().info(f"Received message {msg.data}")


def main(args=None):

    rclpy.init(args=args)

    test_node = TestNode()

    rclpy.spin(test_node)

    test_node.destroy_node()
    rclpy.shutdown()


if __name__ == "__main__":
    main()

setup.py:

from setuptools import find_packages, setup
from os.path import join
from glob import glob

package_name = "minimalpkg"

setup(
    name=package_name,
    version="1.0.0",
    zip_safe=True,
    packages=find_packages(exclude="test"),
    install_requires=["setuptools", "rclpy"],
    tests_require=[],
    data_files=[
        (join("share", package_name), ["package.xml"]),
    ],
    entry_points={
        "scripts": [],
        "console_scripts": ["minimal = minimalpkg.minimalt:main"],
    },
)

package.xml:

<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
    <name>minimalpkg</name>
    <version>1.0.0</version>
    <description>empty</description>
    <maintainer email="dummy@email.com">John Doe</maintainer>
    <license>MIT</license>
    <buildtool_depend>ament_python</buildtool_depend>
    <exec_depend>rclpy</exec_depend>
    <export>
        <build_type>ament_python</build_type>
    </export>
</package>

setup.cfg:

[develop]
script-dir=$base/lib/minimalpkg
[install]
install-scripts=$base/lib/minimalpkg

Error traceback:

Traceback (most recent call last):
  File "/home/warp/ros2_ws/install/minimalpkg/lib/minimalpkg/minimal", line 6, in <module>
    from pkg_resources import load_entry_point
  File "/home/warp/.local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3250, in <module>
    @_call_aside
  File "/home/warp/.local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3234, in _call_aside
    f(*args, **kwargs)
  File "/home/warp/.local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 3263, in _initialize_master_working_set
    working_set = WorkingSet._build_master()
  File "/home/warp/.local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 583, in _build_master
    ws.require(__requires__)
  File "/home/warp/.local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 900, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/home/warp/.local/lib/python3.6/site-packages/pkg_resources/__init__.py", line 786, in resolve
    raise DistributionNotFound(req, requirers)
pkg_resources.DistributionNotFound: The 'rclpy' distribution was not found and is required by minimalpkg
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-10-11 09:18:45 -0500

sansoucie gravatar image

Removing rclpy from the keyword argument install_requires=["setuptools", "rclpy"] in setup.py seems to have fixed the problem.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2019-10-10 18:00:39 -0500

Seen: 3,684 times

Last updated: Oct 11 '19