[python-win32] Bit of a strange one using py2exe
Tim Golden
mail at timgolden.me.uk
Mon May 23 10:17:17 CEST 2011
On 23/05/2011 09:09, Jacob Kruger wrote:
> Not 100% sure if this is for real, but almost seemed like when I
> tried out making use of py2exe to build an executable from a python
> script of mine, it didn't accept the use of a string value of exit in
> single quotes after it had built the executable, as in, something
> like the following, that would work fine in the normal interpreter
> rendition, now told me something along the lines of 'exit' is not
> defined:
Usual recommendation: provide the exact traceback (cut-and-pasted
if at all possible) rather than "something along the lines of...".
My guess is that you used backtick quotes (`) rather than
single quotes. Backticks are a little-used alternative to
the repr () function -- deprecated in Python 3 ISTR. That
would leave the interpreter calling the __repr__ method
of the exit object. The interactive interpreter has an exit
object:
<dump>
ActivePython 2.7.1.4 (ActiveState Software Inc.) based on
Python 2.7.1 (r271:86832, Feb 7 2011, 11:30:38) [MSC v.1500 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> exit
Use exit() or Ctrl-Z plus Return to exit
>>>
</dump>
... which probably comes from site.py (I can't be bothered to check
right now) which isn't imported if Python isn't running interactively.
Such as, within a py2exe bundle.
> Also, going to look through any sort of documentation can find, but,
> off-hand, does py2exe need you to in fact include all code etc. in
> one file?
Nope. I have multifile py2exe bundles, eg:
<code>
from distutils.core import setup
import py2exe
setup (
console=[
dict (script="web_portraits_lrwp.py"),
dict (script="web_contacts_lrwp.py"),
dict (script="web_uaccess_lrwp.py"),
],
data_files=[
(".", ["header.html"]),
],
options={
"py2exe" : {
"includes" : ["decimal"],
"packages" : ["email"],
}
}
)
</code>
Each of those scripts pulls in quite a few other modules,
all of which py2exe picks up and bundles into its library.zip.
TJG
More information about the python-win32
mailing list