AttributeError: 'module' object has no attribute 'main'

asked 2018-11-08 09:07:47 -0600

Ibrahim_aerospace gravatar image

updated 2018-11-12 06:07:10 -0600

Hello all! I want to run turtlebot simulation. It has been complied correctly. But I run the main.launch file it gives me the following error.

Traceback (most recent call last):
      File "/opt/ros/kinetic/lib/xacro/xacro", line 33, in <module>
        xacro.main()
    AttributeError: 'module' object has no attribute 'main'
    while processing /home/ibrahim/catkin_ws/src/turtlebot_simulator/turtlebot_gazebo/launch/includes/kobuki.launch.xml:
    Invalid <param> tag: Cannot load command parameter [turtlebot_description]: command [/opt/ros/kinetic/lib/xacro/xacro --inorder '/home/ibrahim/catkin_ws/src/turtlebot/turtlebot_description/robots/kobuki_hexagons_asus_xtion_pro.urdf.xacro'] returned with code [1]. 

    Param xml is <param command="$(arg urdf_file)" name="turtlebot_description"/>
    The traceback for the exception was written to the log file

In the initial lines it says no attribute main but I visit the address of this xacro.py file and I opened it with my editor like Visual Studio Code or can be opened with some other editors. following are the contents of xacro.py file. some comments are there but with just two lines of code.

import xacro
xacro.main()

So I removed main() and type again to check if it recognizes this function or not. so besides main() there are other attributes like math, macro, message etc appear in the sub menu. So main() function/attribute is there. I visited some similar posts but it didn't help me. If someone has faced this problem and solved it. Please help me to find its solution. Thanks.

when I type /opt/ros/kinetic/lib/xacro/xacro --inorder '/home/ibrahim/catkin_ws/src/turtlebot/turtlebot_description/robots/kobuki_hexagons_asus_xtion_pro.urdf.xacro'. It gives the following info.

<?xml version="1.0" ?>
<!-- =================================================================================== -->
<!-- |    This document was autogenerated by xacro from /home/ibrahim/catkin_ws/src/turtlebot/turtlebot_description/robots/kobuki_hexagons_asus_xtion_pro.urdf.xacro | -->
<!-- |    EDITING THIS FILE BY HAND IS NOT RECOMMENDED                                 | -->
<!-- =================================================================================== -->
<!--
    - Base      : kobuki
    - Stacks    : hexagons
    - 3d Sensor : kinect
-->
<robot name="turtlebot" xmlns:xacro="http://ros.org/wiki/xacro">
  <kobuki/>
  <stack_hexagons parent="base_link"/>
  <sensor_asus_xtion_pro parent="base_link"/>
</robot>

Command for running launch file is

roslaunch gym_construct main.launch

I want to run simulation environment so I can deploy and train turtlebot robot in it. First I need to run this environment and then run the package for turtlebot2. I am using openai_ROS.

edit retag flag offensive close merge delete

Comments

Do you have an alternative Python interpreter installed (Anaconda)? Or Python 3? What is the output of which python and python --version?

Also: source /opt/ros/kinetic/setup.bash && python -c 'import xacro'.

gvdhoorn gravatar image gvdhoorn  ( 2018-11-08 09:14:15 -0600 )edit

@gvdhoorn by typing which python it returns /usr/bin/python, and by typing python --version it gives me python 2.7.12 as I installed python 2.7 and I sourced it source /opt/ros/kinetic/setup.bash && python -c 'import xacro' but the error exits.

Ibrahim_aerospace gravatar image Ibrahim_aerospace  ( 2018-11-08 21:31:34 -0600 )edit

and I sourced it source /opt/ros/kinetic/setup.bash && python -c 'import xacro'

I'm not sure what you mean by that.

Does executing that line result in an error saying ImportError: No module named xacro?

How did you install ROS? Using apt-get (or apt) or did you build from sources?

gvdhoorn gravatar image gvdhoorn  ( 2018-11-09 02:29:00 -0600 )edit

@gvdhoorn bro I installed ROS long time ago I don't remember whether I installed it using apt-get or apt. by typing source /opt/ros/kinetic/setup.bash && python -c 'import xacro' I get nothing display. But this error appears for another package as well. If you can help me, I shall be thankful.

Ibrahim_aerospace gravatar image Ibrahim_aerospace  ( 2018-11-11 22:56:56 -0600 )edit

I am not your bro, but if source /opt/ros/kinetic/setup.bash && python -c 'import xacro' doesn't give you the same error, then at least xacro appears to be installed.

What is the output of dpkg -l | grep xacro?

gvdhoorn gravatar image gvdhoorn  ( 2018-11-12 00:47:26 -0600 )edit

the output is

ii  ros-kinetic-xacro                               1.11.3-0xenial-20180824-125006-0800                   amd64        Xacro (XML Macros) Xacro is an XML macro language.
Ibrahim_aerospace gravatar image Ibrahim_aerospace  ( 2018-11-12 00:54:28 -0600 )edit

Ok. And what is the output of:

/opt/ros/kinetic/lib/xacro/xacro --inorder '/home/ibrahim/catkin_ws/src/turtlebot/turtlebot_description/robots/kobuki_hexagons_asus_xtion_pro.urdf.xacro'
gvdhoorn gravatar image gvdhoorn  ( 2018-11-12 01:01:05 -0600 )edit

Please edit your original question and append the new output.

Do not use comments for it.

gvdhoorn gravatar image gvdhoorn  ( 2018-11-12 02:24:51 -0600 )edit