win32 pyserial requires javax.comm for py2exe?

Roger Binns rogerb at
Tue Jun 29 19:59:09 CEST 2004

Grant Edwards wrote:
> I'm trying to package a small Python program using py2exe.
> Everything works fine until I add an "include serial", then
> py2exe fails because
>   The following modules appear to be missing
>   ['javax.comm']
> Apparently imports a both the posix and java versions
> of things even on a win32 platform?

It is a "feature" of modulefinder which is used by py2exe, cx_Freeze
and several other freezing tools.

modulefinder imports your main script and then scans the bytecode
for all imports.  It has no idea if the imports are in conditionals
and doesn't care.  eg if you do this:

   if False:
     import specialsauce

Then it will always try to add the specialsauce module since that is
visible in the bytecode.  It isn't an error for the module to be missing
as you saw, but there won't be any issue if you then run the frozen program.

Similar things happen for other modules.  For example if you import
urllib (IIRC) you will find that modulefinder also includes the
SSL binary module even though you may never use SSL.  Again, this
is because it was in the bytecode.

I recommend reading the source for the modulefinder module to get a
better understanding of what is happening.

So ultimately it is all harmless and there will be no difference
between running from source and running from frozen.  If it bugs
you at the cosmetic level then you can exclude packages in
the arguments to your freezing tool, as well as delete any
shared libraries that are sucked in you don't want (eg an SSL
one in the earlier example).


More information about the Python-list mailing list