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

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

asbird 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/", 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/", 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)

def main():
    l2pc = Laser2PC()

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


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

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

Are you using something like that?

gvdhoorn gravatar imagegvdhoorn ( 2019-11-19 02:38:52 -0600 )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 imageasbird ( 2019-11-19 03:57:11 -0600 )edit

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

asbird gravatar imageasbird ( 2019-11-19 04:57:57 -0600 )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 imagegvdhoorn ( 2019-11-19 06:25:23 -0600 )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

Should I change python version for future work ?

asbird gravatar imageasbird ( 2019-11-19 07:21:28 -0600 )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 imageasbird ( 2019-11-19 07:29:03 -0600 )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 imagegvdhoorn ( 2019-11-19 08:58:46 -0600 )edit