Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error importing numpy with Python 3 #78

Open
WenjieYan opened this issue Mar 28, 2021 · 2 comments
Open

Error importing numpy with Python 3 #78

WenjieYan opened this issue Mar 28, 2021 · 2 comments
Labels
question Further information is requested

Comments

@WenjieYan
Copy link

WenjieYan commented Mar 28, 2021

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

  • ROS Distro: Neotic
  • OS Version: Ubuntu 20.04
  • Commit: 3ffd736
@tylerjw
Copy link
Member

tylerjw commented Mar 28, 2021

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
Copy link
Contributor

JStech commented Mar 29, 2021

#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.)

@JStech JStech added the question Further information is requested label May 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants