Oprettelse af en Windows Executable med Python 3.2 & cx\_Freeze

Indlæg af Hanne Mølgaard Plasc

Problem



Så jeg forsøger at pakke et python script til en exe, der kan køre på en Windows-maskine uden at have brug for en pythoninstallation. Jeg kører WIn7 & min ansøgning bruger pywin32 & launcher er en fil kaldet console.py, som tager et par kommandolinjeparamenter og udfører et andet script


Jeg oprettede en setup.py-fil, hvorpå jeg kørte python setup.py bygge med følgende installationsfil


from cx\_Freeze import setup, Executable

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


Det returnerede følgende fejl,


Traceback (most recent call last):
  File "C:Python32libsite-packagescx\_FreezeinitscriptsConsole3.py", line 2
7, in <module>
    exec(code, m.\_\_dict\_\_)
  File "console.py", line 1, in <module>
  File "C:UsersVarunDesktopMy DropboxOnePyOMNotifications v0.2
otificati
ons.py", line 1, in <module>
    import application
  File "C:UsersVarunDesktopMy DropboxOnePyOMNotifications v0.2applicatio
n.py", line 1, in <module>
    import ApplicationServer
  File "C:UsersVarunDesktopMy DropboxOnePyOMNotifications v0.2Applicatio
nServer.py", line 5, in <module>
    win32com.client.gencache.Rebuild()
  File "C:Python32libsite-packageswin32comclientgencache.py", line 649, in
 Rebuild
    \_SaveDicts()
  File "C:Python32libsite-packageswin32comclientgencache.py", line 65, in
\_SaveDicts
    f = open(os.path.join(GetGeneratePath(), "dicts.dat"), "wb")
  File "C:Python32libsite-packageswin32comclientgencache.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'


så jeg regnede måske var der et problem at læse ind i zipfile og besluttede at køre bygge uden at skabe library.zip. Så jeg skiftede setup.py til


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")]
)


og nu får jeg følgende fejlmeddelelse:


Traceback (most recent call last):
  File "C:Python32libsite-packagescx\_FreezeinitscriptsConsole3.py", line 2
7, in <module>
    exec(code, m.\_\_dict\_\_)
  File "console.py", line 1, in <module>
  File "C:UsersVarunDesktopMy DropboxOnePyOMNotifications v0.2
otificati
ons.py", line 1, in <module>
    import application
  File "C:UsersVarunDesktopMy DropboxOnePyOMNotifications v0.2applicatio
n.py", line 1, in <module>
    import ApplicationServer
  File "C:UsersVarunDesktopMy DropboxOnePyOMNotifications v0.2Applicatio
nServer.py", line 5, in <module>
    win32com.client.gencache.Rebuild()
  File "C:Python32libsite-packageswin32comclientgencache.py", line 649, in
 Rebuild
    \_SaveDicts()
  File "C:Python32libsite-packageswin32comclientgencache.py", line 65, in
\_SaveDicts
    f = open(os.path.join(GetGeneratePath(), "dicts.dat"), "wb")
  File "C:Python32libsite-packageswin32comclientgencache.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'

Bedste reference


Prøv at inkludere pakken win32com.gen\_py.


Du kan altid se i den oprettede lynlås og se om biblioteket eksisterer (eller som du har gjort - ikke lynlås, indtil alt fungerer godt).


Skift til følgende


#....
executables = [Executable("console.py", packages=[''win32com.gen\_py])]
#....