3

So I'm trying to package a python script into an exe that can run on a Windows machine without needing a python install. I'm running WIn7 & my application uses pywin32 & the launcher is a file called console.py which takes in a couple of command line arguments and executes another script

I created a setup.py file upon which I ran python setup.py build, with the following setup file

from cx_Freeze import setup, Executable

setup(
    name = "OneNote Email Notifications",
    version = "0.1",
    description = "An email notifier for OneNote",
    executables = [Executable("console.py")]
    )

That returned the following error,

Traceback (most recent call last):
  File "C:\Python32\lib\site-packages\cx_Freeze\initscripts\Console3.py", line 2
7, in <module>
    exec(code, m.__dict__)
  File "console.py", line 1, in <module>
  File "C:\Users\Varun\Desktop\My Dropbox\OnePy\OM\Notifications v0.2\notificati
ons.py", line 1, in <module>
    import application
  File "C:\Users\Varun\Desktop\My Dropbox\OnePy\OM\Notifications v0.2\applicatio
n.py", line 1, in <module>
    import ApplicationServer
  File "C:\Users\Varun\Desktop\My Dropbox\OnePy\OM\Notifications v0.2\Applicatio
nServer.py", line 5, in <module>
    win32com.client.gencache.Rebuild()
  File "C:\Python32\lib\site-packages\win32com\client\gencache.py", line 649, in
 Rebuild
    _SaveDicts()
  File "C:\Python32\lib\site-packages\win32com\client\gencache.py", line 65, in
_SaveDicts
    f = open(os.path.join(GetGeneratePath(), "dicts.dat"), "wb")
  File "C:\Python32\lib\site-packages\win32com\client\gencache.py", line 141, in
 GetGeneratePath
    f = open(fname,"w")
IOError: [Errno 2] No such file or directory: 'C:\\Users\\Varun\\Desktop\\My Dro
pbox\\OnePy\\OM\\Notifications v0.2\\build\\exe.win-amd64-3.2\\library.zip\\win3
2com\\gen_py\\__init__.py'

so I figured perhaps there was an issue reading into the zipfile and decided to run build without creating library.zip. So I changed setup.py to

from cx_Freeze import setup, Executable

setup(
    name = "OneNote Email Notifications",
    version = "0.1",
    description = "An email notifier for OneNote",
    options = {"build_exe": {
                                "create_shared_zip": False,
                                "append_script_to_exe": True,
                                "include_in_shared_zip": False,
                             }
              },
    executables = [Executable("console.py")]
)

and now I get the following error message:

Traceback (most recent call last):
  File "C:\Python32\lib\site-packages\cx_Freeze\initscripts\Console3.py", line 2
7, in <module>
    exec(code, m.__dict__)
  File "console.py", line 1, in <module>
  File "C:\Users\Varun\Desktop\My Dropbox\OnePy\OM\Notifications v0.2\notificati
ons.py", line 1, in <module>
    import application
  File "C:\Users\Varun\Desktop\My Dropbox\OnePy\OM\Notifications v0.2\applicatio
n.py", line 1, in <module>
    import ApplicationServer
  File "C:\Users\Varun\Desktop\My Dropbox\OnePy\OM\Notifications v0.2\Applicatio
nServer.py", line 5, in <module>
    win32com.client.gencache.Rebuild()
  File "C:\Python32\lib\site-packages\win32com\client\gencache.py", line 649, in
 Rebuild
    _SaveDicts()
  File "C:\Python32\lib\site-packages\win32com\client\gencache.py", line 65, in
_SaveDicts
    f = open(os.path.join(GetGeneratePath(), "dicts.dat"), "wb")
  File "C:\Python32\lib\site-packages\win32com\client\gencache.py", line 141, in
 GetGeneratePath
    f = open(fname,"w")
IOError: [Errno 2] No such file or directory: 'C:\\Users\\Varun\\Desktop\\My Dro
pbox\\OnePy\\OM\\Notifications v0.2\\build\\exe.win-amd64-3.2\\console.exe\\win3
2com\\gen_py\\__init__.py'
4

1 回答 1

2

Try including the win32com.gen_py package.

You can always look in the created zip and see if the directory exists (or as you have done - don't zip until everything works well).

Change to the following

#....
executables = [Executable("console.py", packages=[''win32com.gen_py])]
#....
于 2011-10-10T05:14:39.513 回答