lcm-proj / lcm

Lightweight Communications and Marshalling
GNU Lesser General Public License v2.1
980 stars 388 forks source link

How to install lcm python? #329

Open sutiwat41 opened 4 years ago

sutiwat41 commented 4 years ago

I have already finished install lcm. Then I want to add lcm to python on window10.

hoxell commented 4 years ago

-DLCM_ENABLE_ PYTHON=ON should do it: https://github.com/lcm-proj/lcm/blob/e7ab2d568510f7ec3018e1e0224c56654a4a42ef/CMakeLists.txt#L55

sutiwat41 commented 4 years ago

I had done it and used py setup.py install, then I had a problem.

LINK : fatal error LNK1181: cannot open input file 'glib-2.0.lib'
error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\VC\\Tools\\MSVC\\14.26.28801\\bin\\HostX86\\x86\\link.exe' failed with exit status 1181
hoxell commented 4 years ago

No need to run that. Just build and install the lcm-python target configured by CMake. Just tried it on Windows 10 Enterprise build 17763 and VS 2017 (Release x64). Had to set BUILD_SHARED_LIBS to OFF and set the /TP compile flag for lcm-test-types-c instead of /TC to get around a few errors, but after that it built and installed just fine.

Make sure PYTHON_EXECUTABLE, PYTHON_INCLUDE_DIR and PYTHON_LIBRARY are correct. CMake automatically configured these values to those of different installations of python for me (executable from msys and the rest from my Anaconda installation), but once I set them manually it worked.

sutiwat41 commented 4 years ago

I had built and installed, and I tested it with python on cmd. import lcm So it errors like this, but I had already add C:\Program Files (x86)\lcm\lib\site-packages to environmental path Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Program Files (x86)\lcm\lib\site-packages\lcm\__init__.py", line 3, in <module> from lcm import _lcm ImportError: DLL load failed while importing _lcm: The specified module could not be found.

hoxell commented 4 years ago

Python doesn't care about PATH like that, so fire up an interactive session and try:

import sys
sys.path.append("C:\Program Files (x86)\lcm\lib\site-packages")
import lcm
lc = lcm.LCM()
sutiwat41 commented 4 years ago

It doesn't work. It has same error.

File "", line 1, in File "C:\Program Files (x86)\lcm\lib\site-packages\lcm__init__.py", line 3, in from lcm import _lcm ImportError: DLL load failed while importing _lcm: The specified module could not be found.

This is my "C:\Program Files (x86)\lcm\lib\site-packages\lcm". image

and This is my "C:\Program Files (x86)\lcm\lib" image

Errors image

hoxell commented 4 years ago

Did you build 64bit or 32bit? I see you're using a 32bit version of Python

sutiwat41 commented 4 years ago

I use py 32 bit and I use 32bit to build.

image image

hoxell commented 4 years ago

Can you share your python related cmake configs as well as the path you've added to to your PATH env variable for libglib-2.0-0.dll?

sutiwat41 commented 4 years ago

This is my glib path image This is my py path image This is my env var image

hoxell commented 4 years ago

Thanks :) You're missing the C:\<msys_installation_dir>\mingw64\bin in your path. libglib-2.0-0.dll needs to be in a location specified in path

sutiwat41 commented 4 years ago

Do you mean changing C:\msys64\mingw32 -> C:\msys64\mingw64 in glib path in cmake?? if I change like that it will be error when build INSTALL

hoxell commented 4 years ago

I forgot to change 64 to 32, but that's not the important part here. I also see now that it wasn't the path you posted, but probably your PYTHONPATH(?). (As a side-note, it's usually not advised to modify the PYTHONPATH) What I mean is that you need to add C:\msys64\mingw32\bin to your actual Path variable, or have you done that already?

sutiwat41 commented 4 years ago

I have already done it in env path and sys path oh sorry the previous post is python path here is my env path image

hoxell commented 4 years ago

Can you check that the cmd instance is using the updated path (i.e. ...mingw32\bin is present)? The only way I'm able to reproduce your issue is when I set the path such that it doesn't contain libglib-2.0-0.dll.

sutiwat41 commented 4 years ago

Should I do something with intl.dll? I hadn't done anything about it. I saw it in https://github.com/lcm-proj/lcm/tree/master/lcm-python

hoxell commented 4 years ago

It's in the same directory as libglib, so it doesn't require any special treatment

sutiwat41 commented 4 years ago

Oh! I don't have intl.dll in mingw32/bin how can i install it ?

hoxell commented 4 years ago

It should be installed with gtk3 if I'm not mistaken (I set it up from scratch this morning and that's the only package I installed). I googled it real quick and got a bunch of hits, so if a simple re-install doesn't fix it, I suggest you google it.

carlschiller commented 3 years ago

I have the same problem as sutiwat41. I tried building lcm 1.4.0 as described by https://github.com/lcm-proj/lcm/issues/256 using VS.

As you mentioned, it should then be enough to build the INSTALL. This does not work, even though the previous CMake configuration finds the correct python instance and glib to generate the vs solution.

I managed to get lcm-gen to work fine, as this part was installed in ProgramFiles (x86)/lcm.

If like sutiwan41 tried to use python setup.py install, I get the exact same problems with not finding LNK1181: cannot open input file 'glib-2.0.lib'.

carlschiller commented 3 years ago

Fixed by downloading gtk using vcpkg, then setting the glib path manually in Cmake. Used the INSTALL solution with VS, then I set the PYTHONPATH environement variable to C:\lcm-1.4.0\build\Lib\site-packages to make python find the library. I also had to copy the files in C:\lcm-1.4.0\build\Lib\site-packages\lcm\Release to C:\lcm-1.4.0\build\Lib\site-packages\lcm for __init__.py to find the .dll

GuoPingPan commented 2 months ago

Fixed by downloading gtk using vcpkg, then setting the glib path manually in Cmake. Used the INSTALL solution with VS, then I set the PYTHONPATH environement variable to C:\lcm-1.4.0\build\Lib\site-packages to make python find the library. I also had to copy the files in C:\lcm-1.4.0\build\Lib\site-packages\lcm\Release to C:\lcm-1.4.0\build\Lib\site-packages\lcm for __init__.py to find the .dll

Bro, I face the problem LINK : fatal error LNK1181: cannot open input file 'glib-2.0.lib'. Do you mean downloading gtk using vcpkg can solve it? Which version of gtk did you use?

GuoPingPan commented 2 months ago

No need to run that. Just build and install the lcm-python target configured by CMake. Just tried it on Windows 10 Enterprise build 17763 and VS 2017 (Release x64). Had to set BUILD_SHARED_LIBS to OFF and set the /TP compile flag for lcm-test-types-c instead of /TC to get around a few errors, but after that it built and installed just fine.

Make sure PYTHON_EXECUTABLE, PYTHON_INCLUDE_DIR and PYTHON_LIBRARY are correct. CMake automatically configured these values to those of different installations of python for me (executable from msys and the rest from my Anaconda installation), but once I set them manually it worked.

@hoxell, hi! I have build the lcm with CMake, but when i try to use mingw32-make to make and install, it cause the error that No targets specified and no makefile found., I also execute generate, the below is output of CMake. Actually, I just want to use lcm-python in windows. I am very look forward to your answer.

CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
Compatibility with CMake < 3.5 will be removed from a future version of
CMake.

Update the VERSION argument <min> value or use a ...<max> suffix to tell
CMake that the project does not need compatibility with older versions.

Building LCM 1.5.0 (ABI v1)
Found Python: D:/miniconda3/python.exe (found version "3.12.4") found components: Interpreter
Found Python: D:/miniconda3/python.exe (found version "3.12.4") found components: Interpreter Development Development.Module Development.Embed
CMake Warning at docs/CMakeLists.txt:5 (message):
Doxygen was not found; documentation generation will be incomplete

Could NOT find Java (missing: Java_JAVA_EXECUTABLE Java_JAR_EXECUTABLE Java_JAVAC_EXECUTABLE Java_JAVAH_EXECUTABLE Java_JAVADOC_EXECUTABLE) (Required is at least version "1.8")
Could NOT find Lua (missing: LUA_LIBRARIES LUA_INCLUDE_DIR) 
Unable to parse the Go version string: 
Could NOT find Go (missing: GO_VERSION GO_PLATFORM GO_ARCH) 
CMake Deprecation Warning at lcm-cmake/lcmUtilities.cmake:32 (cmake_minimum_required):
Compatibility with CMake < 3.5 will be removed from a future version of
CMake.

Update the VERSION argument <min> value or use a ...<max> suffix to tell
CMake that the project does not need compatibility with older versions.
Call Stack (most recent call first):
test/types/CMakeLists.txt:1 (include)

CPack: Packages will be placed under D:/lcm-1.5.0/build/packages
Configuring done (0.3s)
Generating done (0.2s)