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

asked 2019-11-18 16:49:38 -0500

asbird gravatar image

updated 2022-01-22 16:10:10 -0500

Evgeny gravatar image

I'm trying to run the code you can see below and after trying to import do_transform_cloud from tf2_sensor_msgs i receive an error:

Traceback (most recent call last):
  File "/media/wojtek/48ee3ba1-28bb-493d-b2ff-de733667d003/wojtek/Inz/mybot_ws-base_sensors/src/pyros/DMO.py", line 7, in <module>
    from tf2_sensor_msgs.tf2_sensor_msgs import do_transform_cloud
  File "/opt/ros/melodic/lib/python2.7/dist-packages/tf2_sensor_msgs/tf2_sensor_msgs.py", line 30, in <module>
    import PyKDL
ImportError: dynamic module does not define module export function (PyInit_PyKDL)

Ubuntu 18.04 LTS, ROS: Melodic

 #! /usr/bin/env python
import rospy
from nav_msgs.msg import Odometry
from sensor_msgs.msg import PointCloud2 as pc2
from sensor_msgs.msg import LaserScan
from laser_geometry import LaserProjection
from tf2_sensor_msgs.tf2_sensor_msgs import do_transform_cloud
#cloud_out = do_transform_cloud(cloud_in, transform)


class Laser2PC():
    def __init__(self):
        self.laserProj = LaserProjection()
        self.pcPub = rospy.Publisher ("/laserPointCloud",pc2, queue_size=1)
        self.laserSub = rospy.Subscriber ("/mybot/laser/scan",
                LaserScan, self.laserCallback)
    def laserCallback(self, data):
        cloud_out = self.laserProj.projectLaser(data)
        self.pcPub.publish(cloud_out)

def main():
    rospy.init_node('listener_extend')
    l2pc = Laser2PC()
    rospy.spin()

if __name__ == '__main__':
    main()
edit retag flag offensive close merge delete

Comments

File "/media/wojtek/48ee3ba1-28bb-493d-b2ff-de733667d003/wojtek/Inz/mybot_ws-base_sensors/src/pyros/DMO.py"

this looks like some kind of virtual or conda environment or some other isolated setup.

Are you using something like that?

gvdhoorn gravatar image gvdhoorn  ( 2019-11-19 02:38:52 -0500 )edit

This is where is my project folder /Inz and this is path to my other partition /media/wojtek/48ee3ba1-28bb-493d-b2ff-de733667d003/wojtek On my main partition I've got system files

asbird gravatar image asbird  ( 2019-11-19 03:57:11 -0500 )edit

@gvdhoorn I'm thinking if maybe version of python could be the problem ?

asbird gravatar image asbird  ( 2019-11-19 04:57:57 -0500 )edit

Could be, in that case you'll want to tell us which versions of things you are using.

And the output of python --version and which python. And which platform this is (CPU arch), how you installed ROS (and PyKDL), etc.

gvdhoorn gravatar image gvdhoorn  ( 2019-11-19 06:25:23 -0500 )edit

I've uninstalled Anaconda and reinstalled ROS, now everything this is my result of these commands:

wojtek@wojtek-Inspiron-7570:~/inzynierka$ python --version
Python 2.7.15+
wojtek@wojtek-Inspiron-7570:~/inzynierka$ which python
/usr/bin/python

Should I change python version for future work ?

asbird gravatar image asbird  ( 2019-11-19 07:21:28 -0500 )edit

Now when i change to python 3.6 from update-alternatives --config python this error appears

ModuleNotFoundError: No module named 'rospkg'

Should i work on python 2.7.6 or there is a way to make it work on 3.6

asbird gravatar image asbird  ( 2019-11-19 07:29:03 -0500 )edit

The packages distributed with ROS Melodic are only installed for the system-provided, default Python version. For Ubuntu Bionic, that is still Python 2.7. Not 3.6.

gvdhoorn gravatar image gvdhoorn  ( 2019-11-19 08:58:46 -0500 )edit