Issue
I keep getting the ImportError in the title. I think it might be a problem with python 2 and python 3, since on python 2.7 it runs just fine. I need it on python 3 however and keep getting an error and I don't know where to even look to fix it.
There are multiple post about this already but every single one of them found a unique solution that doesn't work for me.
Detail to my project in case there could be an entirely different solution: I am trying to get a YDLidar TG30 and a camera working on a Raspberry Pi 4. I want to make a simple little program with a GUI that workers on a construction site can use to look at the lidar data and save profiles and pictures. For that I wanted to use Python 3 because that's what I know.
Back to the ImportError: When calling import ydlidar
in a python 3 file I get the following error message:
Traceback (most recent call last):
File "/home/pi/.local/lib/python3.7/site-packages/ydlidar.py", line 14, in swig_import_helper
return importlib.import_module(mname)
File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 670, in _load_unlocked
File "<frozen importlib._bootstrap>", line 583, in module_from_spec
File "<frozen importlib._bootstrap_external>", line 1043, in create_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
ImportError: dynamic module does not define module export function (PyInit__ydlidar)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "lidar_test_4.py", line 2, in <module>
import ydlidar
File "/home/pi/.local/lib/python3.7/site-packages/ydlidar.py", line 17, in <module>
_ydlidar = swig_import_helper()
File "/home/pi/.local/lib/python3.7/site-packages/ydlidar.py", line 16, in swig_import_helper
return importlib.import_module('_ydlidar')
File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ImportError: dynamic module does not define module export function (PyInit__ydlidar)
The YDLidar-SDK I'm trying to use can be found on GitHub.
Solution
Well I still don't know what the error is, but I managed to solve it by creating a venv with python 3 and an reinstalling the entire SDK in this env.
Answered By - Ceolando