Problems with import hooks and encoding

V

Vinay Sajip

The simple program

#--------------------------------------
def main():
print repr(u'\u2029'.encode('utf-8'))

if __name__ == "__main__":
main()
#--------------------------------------

works as expected when run from the command-line, but fails when
converted to an executable using PyInstaller. (For example, if the
executable is created on a Ubuntu Jaunty system but then run on a
Ubuntu Hardy system.) Digging into why this happens leads to the
observation that Py_Initialize calls _PyUnicode_Init, which in turn
causes encodings to be imported via the _codecs module (codecs.c).
However, this appears to happen before the import hook machinery is
set up. Is there a way of intercepting the importing of encodings so
that a "freeze" processor like PyInstaller's launcher can redirect the
import to the package bundled with the executable, rather than any
package provided with a host-installed version of Python?

Regards,

Vinay Sajip
 

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,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top