Newbie question on installing lcm python module under windows

450 views
Skip to first unread message

christoph

unread,
Jan 12, 2012, 1:11:56 PM1/12/12
to Lightweight Communications and Marshalling
Hi everybody,

I'm new to lcm but I got it running under Linux and Windows (Windows
Vista + Visual Studio 9). Under Windows the test executables run (lcm-
sink, ...) but I can't get the python module to work. As far as I
understand it, this module has to be built, which would normally be
done via "python setup.py install". This does not work under windows
because the python commands module and pkg-config doesn't seem to
work.

Did anybody of you use the python module under Windows and can give me
a hint how to build it.

Thanks in advance,
Christoph

Albert Huang

unread,
Jan 14, 2012, 1:06:47 AM1/14/12
to lcm-...@googlegroups.com
Hi Christoph,

We haven't done much work on the python module for the Windows port
yet. I'll poke around when I have a chance and see if I can get
something to work.

Albert

> --
> You received this message because you are subscribed to the Google Groups "Lightweight Communications and Marshalling" group.
> To post to this group, send email to lcm-...@googlegroups.com.
> To unsubscribe from this group, send email to lcm-users+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/lcm-users?hl=en.
>

christoph

unread,
Jan 14, 2012, 3:11:35 PM1/14/12
to lcm-...@googlegroups.com
Hi Albert,

thanks for your reply. I started to play around with this issue. I didn't yet make it work but that is probably since I don't know MSVC very well and am not familiar with building python modules. The code seems to need only minor porting and I got it to compile at least. I wasn't able to build the module with disttools and will try to do it manually next week. As soon as it runs, I'll let you know and I can contribute the necessary changes. 

Christoph

christoph

unread,
Jan 16, 2012, 2:07:56 PM1/16/12
to lcm-...@googlegroups.com
Hi Albert,

I just got it running after lots of hacking and trying. I finally built the python module manually (not using disttools), but the solution is not optimal. The code porting itself is not a problem, mostly changing of some includes (e.g. socket -> winsock). I'll summarize the major issues:

1. For building python modules manually, you need to have the python sources installed and you need to compile the module with the same MSVC version, as the one used for building python itself. Depending on the python version you want to use and the MSVC version you have this will probably imply building a specialized python interpreter for usage with lcm for a lot of users.

2. The most elegant way to it would be to use distutils and provide a setup.py script, which works under windows. The problem with this solution is, that the current version of the MSVC distutils generator automatically turns off C++ compilation mode, if the file suffix .c is detected. As it is necessary for the LCM code to be compiled in C++ mode, this does not work.

Possible solutions:
- provide a tutorial how to manually compile the module according to 1). I will do that for me anyway for documentation purposes, so I can also share it here, but this is rather a quick and dirty solution.

- use disttools: There are two possibilities, one could patch the MSVC generator and pre-compile binaries for all major python version which could be distributed from the lcm website. Or one contacts the MSVC generator developer in order to include the possibility to enforce C++ compilation in the setup.py script. Then a setup.py script could be distributed. IMHO this would be the best solution. 

Let me know what you think.I will post a basic tutorial on manually building the module this week. I don't know yet, when I will find the time to take care of the disttools solution.

Ah and finally thanks for sharing your tool, it seems to work very well and seems to be exactly what we have been looking for.

Greetings,
Christoph

Albert Huang

unread,
Jan 19, 2012, 12:04:58 AM1/19/12
to lcm-...@googlegroups.com
Hi Cristoph,

Thanks for the report, I'm sure it will be helpful to others. I agree
that a solution using distutils and a setup.py script would be best.
I also looked into this briefly and ran into some of the same issues
you pointed out, but don't think I'll have much time in the next few
weeks to work on it more. Definitely let us know if you make progress
on it.

Cheers,
Albert

> --
> You received this message because you are subscribed to the Google Groups
> "Lightweight Communications and Marshalling" group.

> To view this discussion on the web visit
> https://groups.google.com/d/msg/lcm-users/-/Gn844k0hyvsJ.

christoph

unread,
Jan 23, 2012, 5:37:30 AM1/23/12
to lcm-...@googlegroups.com
Hi Albert,

I made it work with disttools. It is possible to patch the msvc compiler generator during runtime in the setup.py script. I think that's the solution to go for. When I will have time (probably next week) I will integrate my changes into the setup.py script and make it platform independent. I will provide a full patch based on the current svn head here. 

Greetings,
Christoph

christoph

unread,
Feb 1, 2012, 8:18:55 AM2/1/12
to lcm-...@googlegroups.com
Hi Albert,

I integrated my changes into the source code. Minor changes are needed in the sources of the lcm-python module to port to windows and to comply to the MSVC compiler. The setup.py now has two different instances of the code, one for win and one for *nix. I'm not sure if this can be done more elegantly easily. I tried to use the windows version of pkg-config in order to unify the code but the output of pkg-config didn't fit very well.

After compiling the Release version of lcm, one can execute   python setup.py bdist_msi  to create a windows installer for the python module. 

I tested only on win32 and you need VisualStudio 2008 (9.0) to compile the python module. VS2010 does not work. 

The patch can be found here: http://pastebin.com/iKX1ns9W

Greetings,
Christoph

Albert Huang

unread,
Feb 1, 2012, 11:59:19 PM2/1/12
to lcm-...@googlegroups.com
Hi Christoph,

That's great, thanks for sending in the patch! I was able to get it
to compile, but if I try to do "import lcm" after installing, I get an
ImportError. Is this something you encountered?

C:\>Python26\python.exe
Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import lcm
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python26\lib\site-packages\lcm\__init__.py", line 3, in <module>
import _lcm
ImportError: DLL load failed: The specified module could not be found.
>>>

C:\>dir Python26\Lib\site-packages\lcm\
Volume in drive C is windows
Volume Serial Number is 7FF4-F0D5

Directory of C:\Python26\Lib\site-packages\lcm

02/01/2012 11:55 PM <DIR> .
02/01/2012 11:55 PM <DIR> ..
02/01/2012 11:53 PM 16,384 _lcm.pyd
02/01/2012 11:51 PM 3,664 __init__.py
02/01/2012 11:55 PM 4,708 __init__.pyc
3 File(s) 24,756 bytes
2 Dir(s) 26,555,199,488 bytes free


Albert

> --
> You received this message because you are subscribed to the Google Groups
> "Lightweight Communications and Marshalling" group.
> To view this discussion on the web visit

> https://groups.google.com/d/msg/lcm-users/-/saUoAJKKpxMJ.

christoph

unread,
Feb 2, 2012, 4:57:26 AM2/2/12
to lcm-...@googlegroups.com
Hi Albert,

I encountered the same error. I could solve it by putting the lcm.dll into the windows/system32 directory. As far as I remember, it didn't work by simply adding the directory containing the DLL to the system path (don't know how windows looks for DLL's). Let me know, if this solves your issue too.

Greetings,
Christoph

Albert Huang

unread,
Feb 2, 2012, 11:31:23 PM2/2/12
to lcm-...@googlegroups.com
Hi Christoph,

I created a new branch for incorporating this patch.
http://lcm.googlecode.com/svn/branches/py-win

I modified setup.py so that it compiles all of LCM directly into the
.pyd. This removes the need for carrying lcm.dll around.

Also, the following 3 files need to be available somewhere for the
dynamic linker: intl.dll, libglib-2.0-0.dll, and libgthread-2.0-0.dll.
It would be great if there was an easy way to statically link glib in
as well...

If you have a chance, please check out the branch and see if it builds for you.

This is great, I'm looking forward to merging this into trunk and
getting it into the next release.

Albert

> --
> You received this message because you are subscribed to the Google Groups
> "Lightweight Communications and Marshalling" group.
> To view this discussion on the web visit

> https://groups.google.com/d/msg/lcm-users/-/2tyq59EF-tQJ.

christoph

unread,
Feb 8, 2012, 8:47:55 AM2/8/12
to lcm-...@googlegroups.com
Hi Albert,

your changes build fine on my machines (both linux and windows). Good idea to compile lcm directly into the python module, that's nice, makes it even easier to deploy.

I had a quick look into the possibility of linking all gtk related libraries statically. As far as I understand it, we need static versions of the libraries and the prebuilt ones only have the dynamic versions. The .lib libraries under gtk/lib seem to be import libraries, which actually still depend on the dll's. Maybe I misunderstood something, but for me, it doesn't seem to be easily possible to link those libraries statically.

Greetings,
Christoph

Muhammad Shaheer Munir

unread,
Aug 14, 2018, 4:21:45 AM8/14/18
to Lightweight Communications and Marshalling
Hello. 
I have the lcm.dll and i want to use it in python. how can i work to build this dll for python or directly using in python. help is appreciated!!!
Greetings,
Shaheer
Reply all
Reply to author
Forward
0 new messages