win32 pyserial requires javax.comm for py2exe?

G

Grant Edwards

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 serial.py imports a both the posix and java versions
of things even on a win32 platform?



------------------------------setup.py------------------------------
# setup.py
from distutils.core import setup
import py2exe
setup(console=["testit.py"])
--------------------------------------------------------------------

------------------------------testit.py------------------------------
import serial
print "hello"
---------------------------------------------------------------------

----------------------python setup.py py2exe-------------------------
running py2exe
*** searching for required modules ***
*** parsing results ***
creating python loader for extension '_sre'
creating python loader for extension 'datetime'
creating python loader for extension 'win32file'
creating python loader for extension 'select'
creating python loader for extension 'win32event'
*** finding dlls needed ***
*** create binaries ***
*** byte compile python files ***
skipping byte-compilation of C:\PYTHON23\lib\copy_reg.py to copy_reg.pyc
skipping byte-compilation of C:\PYTHON23\lib\sre_compile.py to sre_compile.pyc
skipping byte-compilation of C:\PYTHON23\lib\locale.py to locale.pyc
byte-compiling C:\cygwin\home\admin\othertools\build\bdist.win32\winexe\temp\_sre.py to _sre.pyc
skipping byte-compilation of C:\PYTHON23\lib\macpath.py to macpath.pyc
skipping byte-compilation of C:\PYTHON23\lib\popen2.py to popen2.pyc
byte-compiling C:\cygwin\home\admin\othertools\build\bdist.win32\winexe\temp\datetime.py to datetime.pyc
skipping byte-compilation of C:\PYTHON23\lib\atexit.py to atexit.pyc
byte-compiling C:\cygwin\home\admin\othertools\build\bdist.win32\winexe\temp\win32file.py to win32file.pyc
skipping byte-compilation of C:\Python23\Lib\site-packages\serial\serialwin32.py to serial\serialwin32.pyc
skipping byte-compilation of C:\Python23\Lib\site-packages\serial\__init__.py to serial\__init__.pyc
skipping byte-compilation of C:\Python23\Lib\site-packages\serial\serialjava.py to serial\serialjava.pyc
byte-compiling C:\cygwin\home\admin\othertools\build\bdist.win32\winexe\temp\select.py to select.pyc
byte-compiling C:\cygwin\home\admin\othertools\build\bdist.win32\winexe\temp\win32event.py to win32event.pyc
skipping byte-compilation of C:\PYTHON23\lib\linecache.py to linecache.pyc
skipping byte-compilation of C:\PYTHON23\lib\sre_constants.py to sre_constants.pyc
skipping byte-compilation of C:\PYTHON23\lib\re.py to re.pyc
skipping byte-compilation of C:\PYTHON23\lib\ntpath.py to ntpath.pyc
skipping byte-compilation of C:\Python23\Lib\site-packages\serial\serialposix.py to serial\serialposix.pyc
skipping byte-compilation of C:\PYTHON23\lib\stat.py to stat.pyc
skipping byte-compilation of C:\PYTHON23\lib\string.py to string.pyc
skipping byte-compilation of C:\PYTHON23\lib\warnings.py to warnings.pyc
skipping byte-compilation of C:\PYTHON23\lib\UserDict.py to UserDict.pyc
skipping byte-compilation of C:\PYTHON23\lib\repr.py to repr.pyc
skipping byte-compilation of C:\PYTHON23\lib\copy.py to copy.pyc
skipping byte-compilation of C:\PYTHON23\lib\types.py to types.pyc
skipping byte-compilation of C:\PYTHON23\lib\posixpath.py to posixpath.pyc
skipping byte-compilation of C:\PYTHON23\lib\FCNTL.py to FCNTL.pyc
skipping byte-compilation of C:\Python23\Lib\site-packages\serial\serialutil.py to serial\serialutil.pyc
skipping byte-compilation of C:\PYTHON23\lib\sre.py to sre.pyc
skipping byte-compilation of C:\PYTHON23\lib\TERMIOS.py to TERMIOS.pyc
skipping byte-compilation of C:\PYTHON23\lib\os2emxpath.py to os2emxpath.pyc
skipping byte-compilation of C:\PYTHON23\lib\_strptime.py to _strptime.pyc
skipping byte-compilation of C:\PYTHON23\lib\calendar.py to calendar.pyc
skipping byte-compilation of C:\Python23\Lib\site-packages\win32\lib\win32con.py to win32con.pyc
skipping byte-compilation of C:\PYTHON23\lib\sre_parse.py to sre_parse.pyc
skipping byte-compilation of C:\PYTHON23\lib\os.py to os.pyc
*** copy extensions ***
*** copy dlls ***
copying C:\Python23\Lib\site-packages\py2exe\run.exe -> C:\cygwin\home\admin\othertools\dist\testit.exe
The following modules appear to be missing
['javax.comm']
 
G

Grant Edwards

Everything works fine until I add an "include serial", then
py2exe fails because

The following modules appear to be missing
['javax.comm']

Apparently serial.py imports a both the posix and java versions
of things even on a win32 platform?

Removing the lines in site-packages/serial/__init__.py that
import the foreign platform stuff (java, posix) fixes things.

Platform-dependant imports are "a bad thing" when you want to
package up stuff with py2exe -- you end up with Mac and Unix
and Java stuff in your distribution since py2exe has no way to
tell which conditional imports to pay attention to.
 
P

Peter Hansen

Grant said:
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']

Actually, you are assuming too much. It's a warning, not a failure.
The .exe file is generated and will run just fine under Windows.

Don't bother editing PySerial! You'll just create a maintenance
hassle for yourself.

-Peter
 
R

Roger Binns

Grant said:
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 serial.py 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).

Roger
 
T

Thomas Heller

Peter Hansen said:
Grant said:
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']

Actually, you are assuming too much. It's a warning, not a failure.
The .exe file is generated and will run just fine under Windows.

Don't bother editing PySerial! You'll just create a maintenance
hassle for yourself.

Right. pyserial probably uses the same code for CPython and Jython,
if you want to avoid the warning you should exclude 'javax.comm' from
the build, either with the '--excludes javax.comm' command line option,
or by passing something like this to the setup function in your build
script:

setup(...
options = {'py2exe': {'excludes': ['javax.comm']}})

Thomas
 
C

Chris Liechti

Thomas Heller said:
Peter Hansen said:
Grant said:
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']

Actually, you are assuming too much. It's a warning, not a failure.
The .exe file is generated and will run just fine under Windows.

Don't bother editing PySerial! You'll just create a maintenance
hassle for yourself.

Right. pyserial probably uses the same code for CPython and Jython,

almost. my package __init__.py has an if "sys.platform" .. and imports the
platform implementation from an other file.

however, as Roger also pointed out, it's the module finder that just
catches all imports. but well, it's maybe a bit inapropriate to follow up
on Thomas' post he sure knows how py2exe works ;-)
if you want to avoid the warning you should exclude 'javax.comm' from
the build, either with the '--excludes javax.comm' command line option,
or by passing something like this to the setup function in your build
script:

setup(...
options = {'py2exe': {'excludes': ['javax.comm']}})

yes. maybe i should put that in the docs... ok, done, i also added a
setup_demo.py for py2exe in the pyserial examples (CVS on pyserial.sf.net)

and the funny part is that Grant now packages a third party module that
contains code from him (with his name in the sources of course, in the
posix implementation)
:)

chris
 
G

Grant Edwards

almost. my package __init__.py has an if "sys.platform" .. and
imports the platform implementation from an other file.

however, as Roger also pointed out, it's the module finder
that just catches all imports. but well, it's maybe a bit
inapropriate to follow up on Thomas' post he sure knows how
py2exe works ;-)
if you want to avoid the warning you should exclude
'javax.comm' from the build, either with the '--excludes
javax.comm' command line option, or by passing something like
this to the setup function in your build script:

setup(...
options = {'py2exe': {'excludes': ['javax.comm']}})

Yup. That's on the list of things to do tomorrow.
yes. maybe i should put that in the docs... ok, done, i also
added a setup_demo.py for py2exe in the pyserial examples (CVS
on pyserial.sf.net)

and the funny part is that Grant now packages a third party
module that contains code from him (with his name in the
sources of course, in the posix implementation) :)

It's a small world. Sort of makes you wonder if there really
are only 9 people left on the planet using RS-232 ports on
PCs...

FWIW, I've just run across a glitch in the win32 pyserial code.
Changing the baud rate on an already open port sets RTS and DTR
back to the "default" state [and of course I need them to stay
where I put them while I change the baud rate because I'm using
them to do something completely non-standard].

I've got a fix figured out but, but I need to clean it up a
bit. That too will have to wait 'til tomorrow because I wasted
half the afternoon figuring out that my desktop machine had
both UARTs configured to use the same I/O range and IRQ.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top