Using Tools/freeze.py on AIX -- having problems

J

jmalone

I have a python script that I need to freeze on AIX 5.1 (customer has
AIX and does not want to install Python). The python script is pretty
simple (the only things it imports are sys and socket).

The README file in the Tools/freeze directory of the Python-2.4.4
distribution says the following (and many other things):



Previous versions of Freeze used a pretty simple-minded algorithm to
find the modules that your program uses, essentially searching for
lines starting with the word "import". It was pretty easy to trick it
into making mistakes, either missing valid import statements, or
mistaking string literals (e.g. doc strings) for import statements.

This has been remedied: Freeze now uses the regular Python parser to
parse the program (and all its modules) and scans the generated byte
code for IMPORT instructions. It may still be confused -- it will not
know about calls to the __import__ built-in function, or about import
statements constructed on the fly and executed using the 'exec'
statement, and it will consider import statements even when they are
unreachable (e.g. "if 0: import foobar").

This new version of Freeze also knows about Python's new package
import mechanism, and uses exactly the same rules to find imported
modules and packages. One exception: if you write 'from package
import *', Python will look into the __all__ variable of the package
to determine which modules are to be imported, while Freeze will do a
directory listing.

One tricky issue: Freeze assumes that the Python interpreter and
environment you're using to run Freeze is the same one that would be
used to run your program, which should also be the same whose sources
and installed files you will learn about in the next section. In
particular, your PYTHONPATH setting should be the same as for running
your program locally. (Tip: if the program doesn't run when you type
"python hello.py" there's little chance of getting the frozen version
to run.)



I have installed Python-2.4.4 on AIX using the procedure:

(logged in as root)
../configure --disable-ipv6 --disable-shared
make
make test
make install

The compiler being used during this process is: VisualAge C++
Professional / C for AIX Compiler, Version 6.

Python seems to install correctly for the most part ("make test" gives
a few messages about things that are not quite right (3 failed tests
(test_mmap, test_pty, & test_resource) and 2 unexpectedly skipped
(test_curses & test_largefile)), but nothing major (all the normal
stuff, including test_socket and test_sys, passed)). Also, the
unfrozen version of the script seems to run properly on the Python
interpreter after installation.

After this paragraph follows the output from the freeze. The biggest
problem is the part at the bottom "Warning: unknown modules remain:".
Neither of the suggestions in the README file in the Tools/freeze
directory about this warning message have proven helpful.



Name File
---- ----
m BaseHTTPServer /usr/local/lib/python2.4/BaseHTTPServer.py
m FixTk /usr/local/lib/python2.4/lib-tk/FixTk.py
m SocketServer /usr/local/lib/python2.4/SocketServer.py
m StringIO /usr/local/lib/python2.4/StringIO.py
m Tkconstants
/usr/local/lib/python2.4/lib-tk/Tkconstants.py
m Tkinter /usr/local/lib/python2.4/lib-tk/Tkinter.py
m UserDict /usr/local/lib/python2.4/UserDict.py
m __builtin__
m __main__ xfer.py
m _codecs
m _locale
/usr/local/lib/python2.4/lib-dynload/_locale.so
m _random
/usr/local/lib/python2.4/lib-dynload/_random.so
m _socket
/usr/local/lib/python2.4/lib-dynload/_socket.so
m _sre
m _threading_local
/usr/local/lib/python2.4/_threading_local.py
m array
/usr/local/lib/python2.4/lib-dynload/array.so
m atexit /usr/local/lib/python2.4/atexit.py
m base64 /usr/local/lib/python2.4/base64.py
m binascii
/usr/local/lib/python2.4/lib-dynload/binascii.so
m cStringIO
/usr/local/lib/python2.4/lib-dynload/cStringIO.so
m codecs /usr/local/lib/python2.4/codecs.py
m collections
/usr/local/lib/python2.4/lib-dynload/collections.so
m copy /usr/local/lib/python2.4/copy.py
m copy_reg /usr/local/lib/python2.4/copy_reg.py
m dis /usr/local/lib/python2.4/dis.py
P distutils
/usr/local/lib/python2.4/distutils/__init__.py
m distutils.dep_util
/usr/local/lib/python2.4/distutils/dep_util.py
m distutils.errors
/usr/local/lib/python2.4/distutils/errors.py
m distutils.log /usr/local/lib/python2.4/distutils/log.py
m distutils.spawn /usr/local/lib/python2.4/distutils/spawn.py
m distutils.sysconfig
/usr/local/lib/python2.4/distutils/sysconfig.py
m distutils.text_file
/usr/local/lib/python2.4/distutils/text_file.py
m distutils.util /usr/local/lib/python2.4/distutils/util.py
m dummy_thread /usr/local/lib/python2.4/dummy_thread.py
P email /usr/local/lib/python2.4/email/__init__.py
m email.Charset /usr/local/lib/python2.4/email/Charset.py
m email.Encoders /usr/local/lib/python2.4/email/Encoders.py
m email.Errors /usr/local/lib/python2.4/email/Errors.py
m email.FeedParser
/usr/local/lib/python2.4/email/FeedParser.py
m email.Generator /usr/local/lib/python2.4/email/Generator.py
m email.Header /usr/local/lib/python2.4/email/Header.py
m email.Iterators /usr/local/lib/python2.4/email/Iterators.py
m email.Message /usr/local/lib/python2.4/email/Message.py
m email.Parser /usr/local/lib/python2.4/email/Parser.py
m email.Utils /usr/local/lib/python2.4/email/Utils.py
m email._parseaddr
/usr/local/lib/python2.4/email/_parseaddr.py
m email.base64MIME
/usr/local/lib/python2.4/email/base64MIME.py
m email.quopriMIME
/usr/local/lib/python2.4/email/quopriMIME.py
P encodings
/usr/local/lib/python2.4/encodings/__init__.py
m encodings.aliases
/usr/local/lib/python2.4/encodings/aliases.py
m errno
m exceptions
m fcntl
/usr/local/lib/python2.4/lib-dynload/fcntl.so
m fnmatch /usr/local/lib/python2.4/fnmatch.py
m formatter /usr/local/lib/python2.4/formatter.py
m ftplib /usr/local/lib/python2.4/ftplib.py
m getopt /usr/local/lib/python2.4/getopt.py
m getpass /usr/local/lib/python2.4/getpass.py
m glob /usr/local/lib/python2.4/glob.py
m gopherlib /usr/local/lib/python2.4/gopherlib.py
m htmlentitydefs /usr/local/lib/python2.4/htmlentitydefs.py
m htmllib /usr/local/lib/python2.4/htmllib.py
m httplib /usr/local/lib/python2.4/httplib.py
m imp
m inspect /usr/local/lib/python2.4/inspect.py
m itertools
/usr/local/lib/python2.4/lib-dynload/itertools.so
m linecache /usr/local/lib/python2.4/linecache.py
m locale /usr/local/lib/python2.4/locale.py
m macpath /usr/local/lib/python2.4/macpath.py
m macurl2path /usr/local/lib/python2.4/macurl2path.py
m markupbase /usr/local/lib/python2.4/markupbase.py
m marshal
m math
/usr/local/lib/python2.4/lib-dynload/math.so
m mimetools /usr/local/lib/python2.4/mimetools.py
m mimetypes /usr/local/lib/python2.4/mimetypes.py
m ntpath /usr/local/lib/python2.4/ntpath.py
m nturl2path /usr/local/lib/python2.4/nturl2path.py
m opcode /usr/local/lib/python2.4/opcode.py
m os /usr/local/lib/python2.4/os.py
m os2emxpath /usr/local/lib/python2.4/os2emxpath.py
m popen2 /usr/local/lib/python2.4/popen2.py
m posix
m posixpath /usr/local/lib/python2.4/posixpath.py
m pwd
m py_compile /usr/local/lib/python2.4/py_compile.py
m pydoc /usr/local/lib/python2.4/pydoc.py
m quopri /usr/local/lib/python2.4/quopri.py
m random /usr/local/lib/python2.4/random.py
m re /usr/local/lib/python2.4/re.py
m repr /usr/local/lib/python2.4/repr.py
m rfc822 /usr/local/lib/python2.4/rfc822.py
m select
/usr/local/lib/python2.4/lib-dynload/select.so
m sgmllib /usr/local/lib/python2.4/sgmllib.py
m site /usr/local/lib/python2.4/site.py
m socket /usr/local/lib/python2.4/socket.py
m sre /usr/local/lib/python2.4/sre.py
m sre_compile /usr/local/lib/python2.4/sre_compile.py
m sre_constants /usr/local/lib/python2.4/sre_constants.py
m sre_parse /usr/local/lib/python2.4/sre_parse.py
m stat /usr/local/lib/python2.4/stat.py
m string /usr/local/lib/python2.4/string.py
m strop
/usr/local/lib/python2.4/lib-dynload/strop.so
m struct
/usr/local/lib/python2.4/lib-dynload/struct.so
m sys
m tempfile /usr/local/lib/python2.4/tempfile.py
m termios
/usr/local/lib/python2.4/lib-dynload/termios.so
m thread
m threading /usr/local/lib/python2.4/threading.py
m time
/usr/local/lib/python2.4/lib-dynload/time.so
m token /usr/local/lib/python2.4/token.py
m tokenize /usr/local/lib/python2.4/tokenize.py
m traceback /usr/local/lib/python2.4/traceback.py
m tty /usr/local/lib/python2.4/tty.py
m types /usr/local/lib/python2.4/types.py
m urllib /usr/local/lib/python2.4/urllib.py
m urlparse /usr/local/lib/python2.4/urlparse.py
m uu /usr/local/lib/python2.4/uu.py
m warnings /usr/local/lib/python2.4/warnings.py
m webbrowser /usr/local/lib/python2.4/webbrowser.py

Missing modules:
? Carbon.File imported from macpath
? Carbon.Folder imported from tempfile
? Carbon.Folders imported from tempfile
? EasyDialogs imported from getpass
? MacOS imported from Tkinter, distutils.sysconfig, py_compile
? SOCKS imported from ftplib
? _emx_link imported from os
? _ssl imported from socket
? _tkinter imported from FixTk, Tkinter
? _winreg imported from urllib
? ce imported from os
? ic imported from pydoc, urllib, webbrowser
? mac imported from os
? msvcrt imported from getpass
? nt imported from ntpath, os
? org.python.core imported from copy
? os.path imported from os
? os2 imported from os
? riscos imported from os
? riscosenviron imported from os
? riscospath imported from os
? rourl2path imported from urllib
? sitecustomize imported from site

freezing BaseHTTPServer ...
freezing FixTk ...
freezing SocketServer ...
freezing StringIO ...
freezing Tkconstants ...
freezing Tkinter ...
freezing UserDict ...
freezing __main__ ...
freezing _threading_local ...
freezing atexit ...
freezing base64 ...
freezing codecs ...
freezing copy ...
freezing copy_reg ...
freezing dis ...
freezing distutils ...
freezing distutils.dep_util ...
freezing distutils.errors ...
freezing distutils.log ...
freezing distutils.spawn ...
freezing distutils.sysconfig ...
freezing distutils.text_file ...
freezing distutils.util ...
freezing dummy_thread ...
freezing email ...
freezing email.Charset ...
freezing email.Encoders ...
freezing email.Errors ...
freezing email.FeedParser ...
freezing email.Generator ...
freezing email.Header ...
freezing email.Iterators ...
freezing email.Message ...
freezing email.Parser ...
freezing email.Utils ...
freezing email._parseaddr ...
freezing email.base64MIME ...
freezing email.quopriMIME ...
freezing encodings ...
freezing encodings.aliases ...
freezing fnmatch ...
freezing formatter ...
freezing ftplib ...
freezing getopt ...
freezing getpass ...
freezing glob ...
freezing gopherlib ...
freezing htmlentitydefs ...
freezing htmllib ...
freezing httplib ...
freezing inspect ...
freezing linecache ...
freezing locale ...
freezing macpath ...
freezing macurl2path ...
freezing markupbase ...
freezing mimetools ...
freezing mimetypes ...
freezing ntpath ...
freezing nturl2path ...
freezing opcode ...
freezing os ...
freezing os2emxpath ...
freezing popen2 ...
freezing posixpath ...
freezing py_compile ...
freezing pydoc ...
freezing quopri ...
freezing random ...
freezing re ...
freezing repr ...
freezing rfc822 ...
freezing sgmllib ...
freezing site ...
freezing socket ...
freezing sre ...
freezing sre_compile ...
freezing sre_constants ...
freezing sre_parse ...
freezing stat ...
freezing string ...
freezing tempfile ...
freezing threading ...
freezing token ...
freezing tokenize ...
freezing traceback ...
freezing tty ...
freezing types ...
freezing urllib ...
freezing urlparse ...
freezing uu ...
freezing warnings ...
freezing webbrowser ...
generating table of frozen modules
Warning: unknown modules remain: _locale _random _socket array binascii
cStringIO collections fcntl itertools math select strop struct termios
time
Now run "make" in xfer to build the target: xfer



After running make, here is the result of trying to execute the frozen
script:



# ./xfer
Traceback (most recent call last):
File "xfer.py", line 2, in ?
File "/usr/local/lib/python2.4/socket.py", line 45, in ?
import _socket
ImportError: No module named _socket
#



Any insight you can provide in regards to this problem would be greatly
appreciated !

Thanks !!!

Sincerely,
John Malone
Optio Software, Inc.
 
N

nnorwitz

Python seems to install correctly for the most part ("make test" gives
a few messages about things that are not quite right (3 failed tests
(test_mmap, test_pty, & test_resource) and 2 unexpectedly skipped

Don't worry about these.
Name File
---- ----
m _locale
/usr/local/lib/python2.4/lib-dynload/_locale.so
m _random
/usr/local/lib/python2.4/lib-dynload/_random.so
m _socket
/usr/local/lib/python2.4/lib-dynload/_socket.so
m array
/usr/local/lib/python2.4/lib-dynload/array.so
m binascii
/usr/local/lib/python2.4/lib-dynload/binascii.so
[...]

generating table of frozen modules
Warning: unknown modules remain: _locale _random _socket array binascii
cStringIO collections fcntl itertools math select strop struct termios
time
Now run "make" in xfer to build the target: xfer

After running make, here is the result of trying to execute the frozen
script:



# ./xfer
Traceback (most recent call last):
File "xfer.py", line 2, in ?
File "/usr/local/lib/python2.4/socket.py", line 45, in ?
import _socket
ImportError: No module named _socket
#

There's this note in freeze.py:

"""
The script should not use modules provided only as shared libraries;
if it does, the resulting binary is not self-contained.
"""

I don't really remember much about freeze. IIRC, you will also need to
copy the extension modules (I left them in above) in addition to
'xfer'. Try copying them into the same directory. You might need to
set LIBPATH=. (or whatever the env't var is). On most Unixes, the
env't var is LD_LIBRARY_PATH, but I recall AIX being different.

If you want, you can just copy all the files from lib-dynload along
with 'xfer'.

HTH,
n
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top