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

does KDL have python3 binding? #115

Closed
foolyc opened this issue Nov 14, 2017 · 24 comments
Closed

does KDL have python3 binding? #115

foolyc opened this issue Nov 14, 2017 · 24 comments

Comments

@foolyc
Copy link

foolyc commented Nov 14, 2017

In python3, how to use KDL? or any other recommended tools?

@ahcorde
Copy link

ahcorde commented Dec 15, 2017

If you compile python_orocos_kdl with catkin using these flags: -DPYTHON_VERSION=3.6 -DPYTHON_EXECUTABLE=/usr/bin/python3.5 you should be able to run it with Python3.

@foolyc
Copy link
Author

foolyc commented Dec 23, 2017

@ahcorde I complie it with py3.5, but when import the module PyKDL, segmentfault will appear.

Then I wrapper it with boost.Python https://github.com/foolyc/PyKDL

@jacknlliu
Copy link

I think it needs a standalone release package for python3.

@zchen24
Copy link
Contributor

zchen24 commented Feb 7, 2018

PyKDL is compatible with Python 3. Tested with Anaconda Python 3.6 version.

image

To build:
image

@smits
Copy link
Member

smits commented Mar 28, 2018

@foolyc I cannot reproduce your problem, building the python bindings as @ahcorde suggests works for me, also when using python 3.5. For the others I wonder how they got everything working without 74c3b80

@milutter
Copy link
Contributor

@zchen24 I cannot install PyKDL for python 3 as you described.

If I try it for the Master branch, PyKDL does not even compile as multiple functions want to access "‘updateInternalDataStructures’", which is not a member function for multiple classes (e.g. class KDL::ChainIkSolverPos_LMA, class KDL::ChainIkSolverVel_wdls)

If I try it for the Release 1.3 branch , I can compile PyKDL and create the *.so. However, if I import the module using python 3.6, I get the following error:

"ImportError: dynamic module does not define module export function (PyInit_PyKDL)"

Do you have any idea what causes the problem?

@zchen24
Copy link
Contributor

zchen24 commented May 13, 2018

@MichaelLutter I can reproduce your error.

Please try this commit 6fe130a

"ImportError: dynamic module does not define module export function (PyInit_PyKDL)"
The compiled version is for Python 2, which does not have this PyInit_PyKDL function.

@zchen24
Copy link
Contributor

zchen24 commented May 13, 2018

@MichaelLutter Can you try the master branch again? Make sure you have a clean build directory for python_orocos_kdl. (e.g. remove your existing build folder and create a new one)

@milutter
Copy link
Contributor

milutter commented May 13, 2018

@zchen24 Thanks for the fast answer. When I try to compile 6fe130a, I get compilation errors. I copied the compilation errors below.

Regarding the Master Branch, this branched has not changed recently. However, I deleted the build folder and built PyKDL from scratch and it still fails with 'updateInternalDataStructures'.

"The compiled version is for Python 2, which does not have this PyInit_PyKDL function." What do you mean by that? Can one make PyKDL work under Python3?

6fe130a Compilation Errors:
/.../orocos_kinematics_dynamics/python_orocos_kdl/build/PyKDL/sipPyKDLpart2.cpp: In function ‘PyObject* meth_ChainIkSolverVel_pinv_nso_getWeights(PyObject*, PyObject*)’:
/.../orocos_kinematics_dynamics/python_orocos_kdl/build/PyKDL/sipPyKDLpart2.cpp:283:46: error: ‘const class KDL::ChainIkSolverVel_pinv_nso’ has no member named ‘getWeights’; did you mean ‘setWeights’?
sipRes = new ::JntArray(sipCpp->getWeights());
^~~~~~~~~~
setWeights
/.../orocos_kinematics_dynamics/python_orocos_kdl/build/PyKDL/sipPyKDLpart2.cpp: In function ‘PyObject* meth_ChainIkSolverVel_pinv_nso_getOptPos(PyObject*, PyObject*)’:
/.../orocos_kinematics_dynamics/python_orocos_kdl/build/PyKDL/sipPyKDLpart2.cpp:310:46: error: ‘const class KDL::ChainIkSolverVel_pinv_nso’ has no member named ‘getOptPos’; did you mean ‘setOptPos’?
sipRes = new ::JntArray(sipCpp->getOptPos());
^~~~~~~~~
setOptPos
/..../orocos_kinematics_dynamics/python_orocos_kdl/build/PyKDL/sipPyKDLpart2.cpp: In function ‘PyObject* meth_ChainIkSolverVel_pinv_nso_getAlpha(PyObject*, PyObject*)’:
/..../orocos_kinematics_dynamics/python_orocos_kdl/build/PyKDL/sipPyKDLpart2.cpp:337:30: error: ‘const class KDL::ChainIkSolverVel_pinv_nso’ has no member named ‘getAlpha’; did you mean ‘setAlpha’?
sipRes = sipCpp->getAlpha();

@zchen24
Copy link
Contributor

zchen24 commented May 13, 2018

I suspect that you did not compile or install orocos_kdl properly. Please remove your orocos_kinematics_dynamics folder altogether. Do a clean checkout of the master branch. And follow the following steps line by line.
image

@milutter
Copy link
Contributor

Sorry, that was my bad, I compiled the PyKDL with the Version shipped in ROS Lunar. When I adapted the KDL location, I can compile 6fe130a without any errors. However, if I copy the resulting *.so to the python packages, I still get the Python Error:

"ImportError: dynamic module does not define module export function (PyInit_PyKDL)"

Is there any way to solve this error?

ccmake_pykdl

@zchen24
Copy link
Contributor

zchen24 commented May 13, 2018 via email

@milutter
Copy link
Contributor

So I figured out, why python 3 wanted to import the python 2 module. I needed to unset my PYTHONPATH as PYTHONPATH did still point to python 2.

However, if I now import the correct PyKDL.so, I get a new error:

ImportError: /.../orocos_kinematics_dynamics/python_orocos_kdl/build/PyKDL.so: undefined symbol: _ZNK3KDL20ChainIkSolverPos_LMA8strErrorEi

@zchen24
Copy link
Contributor

zchen24 commented May 13, 2018 via email

@milutter
Copy link
Contributor

@zchen24 Thanks for the awesome help. It was a problem with the Library Path.

However, I noticed that PyKDL causes a segmentation fault, if you input a string to any PyKDL function. E.g. kdl.Tree('HelloWorld') causes a segmentation fault for me. I guess it has to do with the change from byte strings to unicode strings in Python 3.

Did you ever get PyKDL to completely work under Python3?

@zchen24
Copy link
Contributor

zchen24 commented May 14, 2018

@MichaelLutter

Did you ever get PyKDL to completely work under Python3?
Day in and day out.

I believe you just found a bug,
image

@smits
Copy link
Member

smits commented May 15, 2018

@foolyc I assume this issue can be closed?

@foolyc foolyc closed this as completed May 18, 2018
@asimonov-hitachi
Copy link

i just tried to follow instructions of building python3 version.
Had to install the SIP that I downloaded from their website (version 4.19.17)
After building/installing I get the following error trying to use PyKDL in python:

>>> import PyKDL
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: the sip module implements API v12.0 to v12.4 but the PyKDL module requires API v12.6
>>> 

@asimonov-hitachi
Copy link

actually, realised there was pip-installed sip of wrong version. removed it and the problem is gone

@ritalaezza
Copy link

I suspect that you did not compile or install orocos_kdl properly. Please remove your orocos_kinematics_dynamics folder altogether. Do a clean checkout of the master branch. And follow the following steps line by line.
image

Hi,

I'm sorry to reopen this thread, but I'm having troubles understanding some of the intermediate steps to get PyKDL to work on Python3. Could you post some extra screenshots of the cmake options? Also, could you clarify if this works independently from catkin/ROS? I ask this because in the cmake menu I'm seeing my catkin directory as well as some catkin related options.

Finally, could you clarify the difference between SIP and pybind11, as well as which one I should select and the recommended installation method/version.

@MatthijsBurgh
Copy link
Collaborator

MatthijsBurgh commented May 22, 2020

You could check the travis config file. As both python 2 as python 3 versions are build and tested in travis.
It does not depend on catkin.

There should be no difference in available API between PyBind11 and sip. To be honest I have no idea which one has better performance. I recommend the PyBind11 version. As some sip version have a bug which caused #41. By using PyBind11 you are sure you don't have this bug.

@ritalaezza
Copy link

@MatthijsBurgh Great! Thank you, worked like a charm (when I run this in a clean environment, without all the variables created by the ROS setup file which I had sourced in my .zshrc).

@murtazabasu
Copy link

murtazabasu commented May 25, 2020

Hello I am trying to read a urdf file but I get error as

python3: /build/orocos-kdl-mPkyII/orocos-kdl-1.4.0/python_orocos_kdl/PyKDL/std_string.sip:52: int convertTo_std_string(PyObject*, void**, int*, PyObject*): Assertion PyUnicode_Check(s)' failed.
`
I am using the recommended Ubuntu 20.04 (Focal Fossa) with ROS Noetic

It never used to happen on melodic with python2.7. I am not sure whether its a problem with the package urdf_parser_py or is it with PyKDL?.

I get the error when i try to execute,

from __future__ import print_function
import PyKDL as kdl
import urdf_parser_py.urdf as urdf
    
 with open(filename) as urdfFile:
    return treeFromUrdfModel(urdf.URDF.from_xml_string(urdfFile.read()))

I think my problem is similar to this, #115 (comment)

and I think this is the solution, #145 (comment)

But I am not sure how should I edit and incorporate the changes mentioned above.

My urdf file is,

<?xml version="1.0"?>
    <!-- =================================================================================== -->
    <!-- |    This document was autogenerated by xacro from ur5_joint_limited_robot.urdf.xacro | -->
    <!-- |    EDITING THIS FILE BY HAND IS NOT RECOMMENDED                                 | -->
    <!-- =================================================================================== -->
    <robot name="ur5">
      <gazebo>
        <plugin filename="libgazebo_ros_control.so" name="ros_control">
          <!-- <robotNamespace>/</robotNamespace> -->
          <robotSimType>gazebo_ros_control/DefaultRobotHWSim</robotSimType>
          <legacyModeNS>true</legacyModeNS>
        </plugin>
        <!--
        <plugin name="gazebo_ros_power_monitor_controller" filename="libgazebo_ros_power_monitor.so">
          <alwaysOn>true</alwaysOn>
          <updateRate>1.0</updateRate>
          <timeout>5</timeout>
          <powerStateTopic>power_state</powerStateTopic>
          <powerStateRate>10.0</powerStateRate>
          <fullChargeCapacity>87.78</fullChargeCapacity>     
          <dischargeRate>-474</dischargeRate>
          <chargeRate>525</chargeRate>
          <dischargeVoltage>15.52</dischargeVoltage>
          <chargeVoltage>16.41</chargeVoltage>
        </plugin>

@MatthijsBurgh
Copy link
Collaborator

@Murtaza786-oss Please open a new issue. It is completely not related to the original issue.

@orocos orocos locked as resolved and limited conversation to collaborators May 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants