FAQ
I'm trying to distribute a python program on SunOS 5.8 with python 2.2.1 and
I think I'm having a shared library problem.

I've tried running the 'frozen' program on two different machines and I get
the following error message...

'import site' failed; use -v for traceback
Traceback (most recent call last):
File "vnmrXserver.py", line 1, in ?
File "/usr/local/lib/python2.2/SocketServer.py", line 131, in ?
File "/usr/local/lib/python2.2/socket.py", line 41, in ?
ImportError: No module named _socket


I've read the warning in the freeze README about shared libraries and I do
indeed see the "Warning: unknown modules remain..." message.

So I guess I this means I have to rebuild python with static linking (this
is a mystery to me) OR is there a way to hack the makefile (or perhaps some
other file) and have the missing modules found and included in the frozen
program without a rebuild of python?

Search Discussions

  • Skip Montanaro at Aug 4, 2003 at 6:39 pm
    David> 'import site' failed; use -v for traceback
    David> Traceback (most recent call last):
    David> File "vnmrXserver.py", line 1, in ?
    David> File "/usr/local/lib/python2.2/SocketServer.py", line 131, in ?
    David> File "/usr/local/lib/python2.2/socket.py", line 41, in ?
    David> ImportError: No module named _socket

    Is this during the freeze operation or while running the frozen app?
    Can you successfully execute

    import _socket

    from the Python interpreter prompt? _socket.so should live in

    ${prefix}/lib/python2.3/lib-dynload

    David> So I guess I this means I have to rebuild python with static
    David> linking (this is a mystery to me) OR is there a way to hack the
    David> makefile (or perhaps some other file) and have the missing
    David> modules found and included in the frozen program without a
    David> rebuild of python?

    You can fairly easily (though a bit tediously) build a static Python
    interpreter. You need to edit Modules/Setup to uncomment the various
    extension modules you need. This is what we all used to do before Greg Ward
    began attempting world domination through distutils. There should be some
    documentation somewhere still about how to do this, perhaps in the
    introductory comments in Modules/Setup itself. Yeah, looks like it's there.

    I don't know about the second half of your question, as I'm not a freeze
    user. Two suggestions come to mind:

    1. Try Gordon MacMillan's installer instead of freeze. (Dunno if it
    works on Solaris.)

    2. Use Sun's package manager to distribute your application along with
    Python instead. Having done this recently for a non-Python app, I
    can tell you this isn't fun, but it should be possible.

    Skip
  • David Detlefsen at Aug 4, 2003 at 6:59 pm

    On 8/4/03 2:39 PM, "Skip Montanaro" wrote:
    David> 'import site' failed; use -v for traceback
    David> Traceback (most recent call last):
    David> File "vnmrXserver.py", line 1, in ?
    David> File "/usr/local/lib/python2.2/SocketServer.py", line 131, in ?
    David> File "/usr/local/lib/python2.2/socket.py", line 41, in ?
    David> ImportError: No module named _socket

    Is this during the freeze operation or while running the frozen app?
    This happens when I try to run the frozen application on a computer that
    doesn't have python.
    Can you successfully execute

    import _socket
    I can indeed run it where I freeze it (both the .py script and the frozen
    application) and import _socket (of course) works fine.
    from the Python interpreter prompt? _socket.so should live in

    ${prefix}/lib/python2.3/lib-dynload

    David> So I guess I this means I have to rebuild python with static
    David> linking (this is a mystery to me) OR is there a way to hack the
    David> makefile (or perhaps some other file) and have the missing
    David> modules found and included in the frozen program without a
    David> rebuild of python?

    You can fairly easily (though a bit tediously) build a static Python
    interpreter. You need to edit Modules/Setup to uncomment the various
    extension modules you need. This is what we all used to do before Greg Ward
    began attempting world domination through distutils. There should be some
    documentation somewhere still about how to do this, perhaps in the
    introductory comments in Modules/Setup itself. Yeah, looks like it's there.
    Wait...I thought it was my turn to dominate the world!

    And it's been a while since I've installed python on a SparcStation and
    indeed, I may have found the binaries somewhere...are there any good places
    that describe more explicitly how to build a static python?
  • Skip Montanaro at Aug 4, 2003 at 7:15 pm
    David> are there any good places that describe more explicitly how to
    David> build a static python?

    I think Modules/Setup is about it. If I had to do this today, here's what
    I'd do.

    1. Starting from a clean source tree, run the 'script' command to get
    a log of the session in a file named 'typescript'.

    2. Exit the script session.

    3. Run the usual 'configure ; make' commands.

    4. Edit Modules/Setup, uncommenting those modules which you want built
    statically. Many are simple and require no extra compile or link
    flags. For others, use the build commands found in the typescript
    file to identify -I..., -L..., and -l... flags. Obviously, omit or
    modify any flags that would be used to generate a shared library
    (-shared, -Bshared, -fPIC, etc).

    5. Run 'make clean ; make'

    6. Test the resulting executable.

    7. Repeat steps 4-6 as necessary.

    8. Congratulate yourself on a job well done and buy yourself a beer.

    If that is an unappealing process for some reason, try this shortcut:

    1. Pay a consultant to do it.

    2. Get other work done.

    3. Congratulate your consultant on a job well done and buy both of you a
    beer.

    There is a third, somewhat longer term, alternative:

    1. Teach distutils how to build a static Python executable.

    2. Submit a patch to SF.

    3. Buy yourself two beers.

    Skip
  • David Detlefsen at Aug 7, 2003 at 3:50 pm
    On 8/4/03 3:15 PM, "Skip Montanaro" wrote:

    Thanks Skip for the following....
    I think Modules/Setup is about it. If I had to do this today, here's what
    I'd do.

    1. Starting from a clean source tree, run the 'script' command to get
    a log of the session in a file named 'typescript'.

    2. Exit the script session.

    3. Run the usual 'configure ; make' commands.

    4. Edit Modules/Setup, uncommenting those modules which you want built
    statically. Many are simple and require no extra compile or link
    flags. For others, use the build commands found in the typescript
    file to identify -I..., -L..., and -l... flags. Obviously, omit or
    modify any flags that would be used to generate a shared library
    (-shared, -Bshared, -fPIC, etc).

    5. Run 'make clean ; make'

    6. Test the resulting executable.

    7. Repeat steps 4-6 as necessary.

    8. Congratulate yourself on a job well done and buy yourself a beer.
    I'm to the point where two modules are not found by freeze:

    Warning: unknown modules remain: pcre strop

    There is no mention of these in my Modules/Setup file. Any suggestions.

    Dave
  • Skip Montanaro at Aug 7, 2003 at 5:09 pm
    Dave> I'm to the point where two modules are not found by freeze:

    Dave> Warning: unknown modules remain: pcre strop

    Dave> There is no mention of these in my Modules/Setup file. Any
    Dave> suggestions.

    I think you can probably omit both, though if freeze is figuring things out
    for you automagically, you may need to tweak Lib/string.py and Lib/re.py to
    dispense with them. The strop module is an extension module which used to
    be used to speed up the string module. With string methods it's no longer
    needed. It's in Modules/stropmodule.c. Pcre is pretty kaput as well. That
    was the first incarnation of Perl-compatible regular expressions, since
    replaced by the new sre module. It's in Modules/pcremodule.c. I suspect
    Modules/pypcre.c is part of the mix as well.

    Skip
  • David Detlefsen at Aug 7, 2003 at 8:40 pm

    On 8/7/03 1:09 PM, "Skip Montanaro" wrote:
    Dave> I'm to the point where two modules are not found by freeze:

    Dave> Warning: unknown modules remain: pcre strop

    Dave> There is no mention of these in my Modules/Setup file. Any
    Dave> suggestions.

    I think you can probably omit both, though if freeze is figuring things out
    for you automagically, you may need to tweak Lib/string.py and Lib/re.py to
    dispense with them. The strop module is an extension module which used to
    be used to speed up the string module. With string methods it's no longer
    needed. It's in Modules/stropmodule.c. Pcre is pretty kaput as well. That
    was the first incarnation of Perl-compatible regular expressions, since
    replaced by the new sre module. It's in Modules/pcremodule.c. I suspect
    Modules/pypcre.c is part of the mix as well.

    Skip
    I think I'm all set with Freeze with a static python build.

    Just to summarize and close the loop on this, here's what I did:

    1. Modified Modules/Setup uncommenting as many modules I could find that
    freeze was complaining about (this took care of all but strop and pcre)

    2. Commented out references to strop in all Lib/*.py it existed in which
    included only string.py and stringold.py (python 2.2.1)

    3. Removed (actually renamed) Modules/pre.py...not sure why this was
    getting included in my build since re.py had an if/else that should have
    caused sre to be imported (and presumably eliminating the dependency on
    pcre) instead of pre...not sure if that makes sense.

    4. Did a 'make clean' and a 'make' to a static python

    5. Freeze my python program without any Warning: unknown modules error

    Dave
  • Zooko at Aug 6, 2003 at 2:11 pm
    Skip:

    Thank you very much for posting this recipe. It happens to be exactly what
    I need right now.

    I think maybe steps 2 and 3 are in reversed order.

    Regards,

    Zooko

    Skip Montanaro wrote:
    I think Modules/Setup is about it. If I had to do this today, here's what
    I'd do.

    1. Starting from a clean source tree, run the 'script' command to get
    a log of the session in a file named 'typescript'.

    2. Exit the script session.

    3. Run the usual 'configure ; make' commands.

    4. Edit Modules/Setup, uncommenting those modules which you want built
    statically. Many are simple and require no extra compile or link
    flags. For others, use the build commands found in the typescript
    file to identify -I..., -L..., and -l... flags. Obviously, omit or
    modify any flags that would be used to generate a shared library
    (-shared, -Bshared, -fPIC, etc).

    5. Run 'make clean ; make'

    6. Test the resulting executable.

    7. Repeat steps 4-6 as necessary.

    8. Congratulate yourself on a job well done and buy yourself a beer.
  • Skip Montanaro at Aug 6, 2003 at 2:28 pm
    zooko> Thank you very much for posting this recipe. It happens to be
    zooko> exactly what I need right now.

    Glad to hear.

    zooko> I think maybe steps 2 and 3 are in reversed order.

    Yeah, dumbo mistako.

    Skip

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedAug 4, '03 at 5:04p
activeAug 7, '03 at 8:40p
posts9
users3
websitepython.org

People

Translate

site design / logo © 2022 Grokbase