importing python module from another in the same catkin package

asked 2021-12-04 15:44:32 -0500

bhomaidan gravatar image

following this Tutorial I built my package, but I wasn't able to import the functions from another module

from utils import *!

when I run the node after compiling successfully I get the following error:

Importerror: cannot import name 'sys_init' from 'utils'

Can you please tell me how to import the functions from the other module successfully?

  • I have the following folders structure:

    my_package __ src/__init__.py
          |__ scripts/utils.py
          |__ nodes/my_node.py
          |__ CmakeLists.txt
          |__ package.xml
          |__ setup.py
    

This is my setup.py file:

#!/usr/bin/python3

from distutils.core import setup
from catkin_pkg.python_setup import generate_distutils_setup

# fetch values from package.xml
setup_args = generate_distutils_setup(
    packages=['yumi_motion_api'],
    package_dir={'': 'src'},
    scripts=['scripts/utils.py'],
    requires=['rospy', 'moveit_core', 'moveit_commander', 'moveit_msgs', 'moveit_ros_planning_interface', 'std_msgs',
              'geometry_msgs','sensor_msgs', 'rospy_message_converter','tf','message_generation', 'message_runtime',
               'abb_robot_driver']
)

setup(**setup_args)

and here is my CmakeLists.txt:

cmake_minimum_required(VERSION 3.0.2)
project(yumi_motion_api)

find_package(catkin REQUIRED COMPONENTS
  rospy
  tf
  std_msgs
  geometry_msgs
  sensor_msgs
  moveit_core
  moveit_ros_planning
  moveit_ros_planning_interface
  rospy_message_converter
  message_generation
)

catkin_python_setup()
catkin_package(CATKIN_DEPENDS rospy std_msgs)
catkin_package(
 CATKIN_DEPENDS rospy std_msgs tf geometry_msgs sensor_msgs moveit_core moveit_ros_planning_interface rospy_message_converter abb_robot_driver
)
include_directories(
  nodes
  src
  scripts
  ${catkin_INCLUDE_DIRS}
)
catkin_install_python(PROGRAMS
  scripts/utils.py
  nodes/yumi_motion_api_node.py
  DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)

and here is my package.xml:

<?xml version="1.0"?>
<package format="2">
  <name>yumi_motion_api</name>
  <version>0.0.0</version>
  <description>The yumi_motion_api package</description>

  <maintainer email="s@s.com">belal</maintainer>

  <license>LGPLv2.1</license>

  <buildtool_depend>catkin</buildtool_depend>

  <build_depend>rospy</build_depend>
  <build_depend>std_msgs</build_depend>
  <build_depend>message_generation</build_depend>
  <build_depend>geometry_msgs</build_depend>
  <build_depend>sensor_msgs</build_depend>
  <build_depend>tf</build_depend>

  <depend>moveit_core</depend>
  <depend>moveit_ros_planning_interface</depend>
  <depend>rospy_message_converter</depend>
  <depend>abb_robot_driver</depend>

  <build_export_depend>rospy</build_export_depend>
  <build_export_depend>message_generation</build_export_depend>
  <build_export_depend>std_msgs</build_export_depend>
  <build_export_depend>geometry_msgs</build_export_depend>
  <build_export_depend>sensor_msgs</build_export_depend>
  <build_export_depend>tf</build_export_depend>

  <exec_depend>rospy</exec_depend>
  <exec_depend>message_runtime</exec_depend>
  <exec_depend>std_msgs</exec_depend>
  <exec_depend>geometry_msgs</exec_depend>
  <exec_depend>sensor_msgs</exec_depend>
  <exec_depend>tf</exec_depend>
  <exec_depend>moveit_commander</exec_depend>

  <!-- The export tag contains other, unspecified, tags -->
  <export>
    <!-- Other tools can request additional information be placed here -->

  </export>
</package>
edit retag flag offensive close merge delete

Comments

I know you ask for importing modules in the same catkin package, but maybe this tutorial for importing module from other packages could help you at least start debugging

ljaniec gravatar image ljaniec  ( 2021-12-07 02:29:01 -0500 )edit