moveit / moveit_calibration

Hand-eye calibration tools for robot arms.
BSD 3-Clause "New" or "Revised" License
143 stars 79 forks source link

Error importing numpy with Python 3 #78

Open WenjieYan opened 3 years ago

WenjieYan commented 3 years ago

Description

While running the calibration, the plugin reports an issue of importing numpy

[ERROR] [1616890018.137078130]: Error importing numpy:

Which refers to the code:

bool HandEyeSolverDefault::solve(const std::vector<Eigen::Isometry3d>& effector_wrt_world,
                                 const std::vector<Eigen::Isometry3d>& object_wrt_sensor, SensorMountType setup,
                                 const std::string& solver_name)
{
  // Check the size of the two sets of pose sample equal
  if (effector_wrt_world.size() != object_wrt_sensor.size())
  {
    ROS_ERROR_STREAM_NAMED(LOGNAME, "The sizes of the two input pose sample "
                                    "vectors are not equal: "
                                    "effector_wrt_world.size() = "
                                        << effector_wrt_world.size()
                                        << " and object_wrt_sensor.size() == " << object_wrt_sensor.size());
    return false;
  }

  auto it = std::find(solver_names_.begin(), solver_names_.end(), solver_name);
  if (it == solver_names_.end())
  {
    ROS_ERROR_STREAM_NAMED(LOGNAME, "Unknown handeye solver name: " << solver_name);
    return false;
  }

  char program_name[7] = "python";
#if PY_MAJOR_VERSION >= 3
  Py_SetProgramName(Py_DecodeLocale(program_name, NULL));
#else
  Py_SetProgramName(program_name);
#endif
  static bool numpy_loaded{ false };
  if (!numpy_loaded)  // Py_Initialize() can only be called once when numpy is
                      // loaded, otherwise will segfault
  {
    Py_Initialize();
    atexit(Py_Finalize);
    numpy_loaded = true;
  }
  ROS_DEBUG_STREAM_NAMED(LOGNAME, "Python C API start");

  // Load numpy c api
  if (_import_array() < 0)
  {
    ROS_ERROR_STREAM_NAMED(LOGNAME, "Error importing numpy: ");
    return false;
  }

I noticed that ROS neotic has switched to Python 3 and I believe in thie calibration tool is still using python 2. Is there any plan to update it? (At least in the CMakeLists.txt it is still searching for python 2)

Your environment

tylerjw commented 3 years ago

This is also an issue because Ubuntu 20.04 is using python3. It seems like it would be a nearly trivial change, would you propose a PR for this?

JStech commented 3 years ago

21 added support for Python 3, and I've run MoveIt Calibration on noetic. Are you sure you have NumPy installed?

Also, please format the code in your post--it is very hard to read otherwise. In-line code is marked with single backticks, and code blocks are marked with triple backticks. (The formatting manual is here.)