Giter Club home page Giter Club logo

Comments (4)

JohnRudolfLewis avatar JohnRudolfLewis commented on September 2, 2024

Re-created problem here: https://github.com/JohnRudolfLewis/bazel-ros-example

ModuleNotFoundError: No module named 'rospy'

$ bazel run //chatter:chatter
INFO: Analyzed target //chatter:chatter (1 packages loaded, 16 targets configured).
INFO: Found 1 target...
Target //chatter:chatter up-to-date:
  bazel-bin/chatter/chatter
  bazel-bin/chatter/chatter_launch.py
INFO: Elapsed time: 0.945s, Critical Path: 0.03s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
INFO: Running command line: bazel-bin/chatter/chatter
... logging to /home/vscode/.ros/log/a64df9b8-4eb5-11ef-b119-bf9446a06087/roslaunch-edfa49feca88-51089.log
Checking log directory for disk usage. This may take a while.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://edfa49feca88:37901/

SUMMARY
========

NODES
  /
    listener (chatter/listener)
    listenerpy (chatter/listener.py)
    talker (chatter/talker)

auto-starting new master
process[master]: started with pid [51800]
ROS_MASTER_URI=http://localhost:11311/

setting /run_id to a64df9b8-4eb5-11ef-b119-bf9446a06087
process[rosout-1]: started with pid [51811]
started core service [/rosout]
process[talker-2]: started with pid [51816]
process[listener-3]: started with pid [51817]
process[listenerpy-4]: started with pid [51818]
Traceback (most recent call last):
  File "/home/vscode/.cache/bazel/_bazel_vscode/0cd11761e4a882ffd46b0cb0705acf1d/execroot/_main/bazel-out/k8-fastbuild/bin/chatter/chatter.runfiles/_main/chatter/listener.py", line 6, in <module>
    import rospy
ModuleNotFoundError: No module named 'rospy'
[listenerpy-4] process has died [pid 51818, exit code 1, cmd chatter/listener.py __name:=listenerpy __log:=/home/vscode/.ros/log/a64df9b8-4eb5-11ef-b119-bf9446a06087/listenerpy-4.log].
log file: /home/vscode/.ros/log/a64df9b8-4eb5-11ef-b119-bf9446a06087/listenerpy-4*.log

from rules_ros.

JohnRudolfLewis avatar JohnRudolfLewis commented on September 2, 2024

In order to launch a python node from a launch file I had to add a shebang to the top of the python file and mark it as executable. The only shebang that I got working so far was #!/usr/bin/env python3. My current suspicion is this is part of the issue.

FYI: If I remove the shebang like the examples in this repo suggest, I get the following error:

RLException: Unable to launch [listenerpy-4]. 
If it is a script, you may be missing a '#!' declaration at the top.
The traceback for the exception was written to the log file

from rules_ros.

JohnRudolfLewis avatar JohnRudolfLewis commented on September 2, 2024

Adding @ros_comm//:rospy to third_party/ros/roslaunch/BUILD.bazel fixes the 'No module named 'rospy' error.

diff --git a/third_party/ros/roslaunch/BUILD.bazel b/third_party/ros/roslaunch/BUILD.bazel
index 06e19d2..09cdf2d 100644
--- a/third_party/ros/roslaunch/BUILD.bazel
+++ b/third_party/ros/roslaunch/BUILD.bazel
@@ -45,7 +45,6 @@ py_library(
         "//third_party/ros:roslib",
         "@ros_comm//:rosmaster",
         "@ros_comm//:rosparam",
-        "@ros_comm//:rospy",
         "@ros_comm_msgs//:py_rosgraph_msgs",
         "@ros_ros//:rosclean",
         requirement("pyyaml"),

But then if you are importing other types in your python script, message definitions for example, those imports will not work right. Still more work to do.

from rules_ros.

JohnRudolfLewis avatar JohnRudolfLewis commented on September 2, 2024

needed to adjust the way that the message def was being imported such that it worked when being launched both directly and via the launch file. Submitted PR.

from rules_ros.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.