lcm-proj / lcm

Lightweight Communications and Marshalling
GNU Lesser General Public License v2.1
1.01k stars 393 forks source link

Python unable to find lcm._lcm #299

Open Tdogb opened 5 years ago

Tdogb commented 5 years ago

Using latest release version on Ubuntu 16.04

Python 3.5.2 (default, Oct  8 2019, 13:06:37) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import lcm
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/sa-zhao/Downloads/lcm-1.4.0/lcm-python/lcm/__init__.py", line 3, in <module>
    from ._lcm import LCM, LCMSubscription
ImportError: No module named 'lcm._lcm'
>>> 
hoxell commented 5 years ago

Have you confirmed that cmake reported that all python paths were properly configured?

contagon commented 4 years ago

Did you ever find a solution to this? I'm getting the same error as well, Ubuntu 20.04.

hoxell commented 4 years ago

I've tried to reproduce this on Ubuntu 18.04. CMake picked up the wrong python config (python 2.7 as executable but python3.6 libs), but that triggered different errors and could be fixed by setting the variables correctly. (python3 setup.py install, on the other hand, worked like a charm.)
The only way I managed to trigger the very same error was if I navigated to the lcm-python directory and tried to import lcm. Python would then try to import the local lcm folder instead of the installed lcm package. In that case __init__.py will raise the exception ('cause there's no _lcm in that folder/"package"). If that's not the case for you, could you provide some more info how to reproduce your issue?

adrian-bodenmann commented 4 years ago

I ran into the same error after installing LCM as described on https://lcm-proj.github.io/build_instructions.html, the reason being that it defaulted to installing for python (Python 2) but not for python3. As hoxovic indicated, setup.py has to be called from python3 install LCM for python3 as well, so after having installed LCM according to the instructions on https://lcm-proj.github.io/build_instructions.html do

cd ../lcm-python
sudo python3 setup.py install

It would be helpful to have a note regarding this in the instruction manual.

Jelly123456 commented 3 years ago

when I run "sudo python3 setup.py install" command, I face the below error:

image

Anyone can help?

If I run "sudo python setup.py install", it can compile successfully, but I will have the same error as @Tdogb when importing lcm.

adrian-bodenmann commented 3 years ago

It looks like you are missing the Python header files. You can install them by running sudo apt install python3-dev