Python own Message Load Problem - ImportError: unknown location - Windows 10

asked 2021-12-10 04:38:43 -0500

Hi together,

I have a trouble with ROS - noetic on WIndos 10. In the text following i try to explain my problem. Thanks for your help.

Side Informations:


The first problem was, if I start my beginner_tutorials talker.py there came an Error:

rosrun beginner_tutorials scripts/talker.py

Error:

The command ""\python.exe"" is either misspelled or could not be found.

I solved it with: Add User Variable: PYTHONHOME - C:\opt\ros\noetic\x64


Then came the next Error if I run:

rosrun beginner_tutorials scripts/talker.py

Error:

[rosrun] Couldn't find executable named scripts/talker.py

I solved it with: Add User Variable: PYTHONPATH - C:\opt\ros\noetic\x64\share


Now I can start the beginner_tutorials script talker.py from the ROS Tutorial - Writing Publisher and Subscriber with Python with:

rosrun beginner_tutorials scripts/talker.py

The next step for me was to test an own msg-File:

I added a new message file Num.msg

I'am adding with the Tutorial the parameters needed in package.xml and CMakeLists.txt. I made some changes in the talker.py for using my own msg-File. I run the setup.bat in devel-folder and run catkin_make.

Then I try to start:

rosrun beginner_tutorials scripts/talker.py

The Error:

Traceback (most recent call last):Traceback (most recent call last):
   File "c:\opt\ros\noetic\x64\share\beginner_tutorials\scripts\talker.py", line 41, in <module>
    from beginner_tutorials.msg import Num
ImportError: cannot import name 'Num' from 'beginner_tutorials.msg' (unknown location)

I have checked the files several times and tested the package on a Ubuntu System. There it works. I tested before run "rosrun" do "roscd".

Did anybody have an idea?

Thanks a lot.


files of the Package:

  • beginner_tutorials
    • msg
      • Num.msg
    • scripts
      • talker.py
    • CMakeLists.txt
    • package.xml

my Num.msg:

int64 Num

my talker.py script:

#!/usr/bin/env python
import rospy
from std_msgs.msg import String
from beginner_tutorials.msg import Num

def talker():
    pub = rospy.Publisher('chatter', Num, queue_size=10)
    rospy.init_node('talker', anonymous=True)
    rate = rospy.Rate(10) # 10hz
    while not rospy.is_shutdown():
        hello_str = 5
        rospy.loginfo(hello_str)
        pub.publish(hello_str)
        rate.sleep()

if __name__ == '__main__':
    try:
        talker()
    except rospy.ROSInterruptException:
        pass

my package.xml (without Standard comments):

<?xml version="1.0"?>
<package format="2">
  <name>beginner_tutorials</name>
  <version>0.0.0</version>
  <description>My_Test_package</description>

  <maintainer email="asdf@asdf.de">Name</maintainer>

  <license>TODO</license>
  <buildtool_depend>catkin</buildtool_depend>
  <build_depend>roscpp</build_depend> ...
(more)
edit retag flag offensive close merge delete

Comments

Try: from beginner_tutorials.msg import num instead

osilva gravatar image osilva  ( 2021-12-10 10:43:21 -0500 )edit

The message String from standard messages is capitalized but num.msg message in the begginner_tutorialsis not. https://github.com/kunal15595/ros/tre...

osilva gravatar image osilva  ( 2021-12-10 10:44:35 -0500 )edit