Hey guys, I posted earlier about py2exe not working in general. Now I got it to actually run, but the .exe produced does not work... Any help would be appreciated. Thanks.

Info:

I've tried various things to solve this issue, but no luck. When I run my setup.bat file, which looks like this:

python setup.py py2exe --bundle 1

Everything seems to run okay, but the resulting .exe produces a "Windows has encountered an error."

My setup.py looks like this:

from distutils.core import setup
import py2exe

setup(console=['ReformatterV2.py'])

I've also tried moving my imports from the actual python script to the setup.py, but that didn't help either. I also tried simply running it from the command line without using --bundle 1. Still no luck.

Inside the produced dist directory, there are four files:

tcl (folder) - 7.08 MB
ReformatterV2.exe - 23 KB
library.zip - 6,921 KB
w9xpopen.exe - 49 KB

It seems very strange to me that the produced exe is only 23 KB (my original script was 10KB)... What could I be doing wrong? Any help is appreciated!

Here's an update.

I found this URL which told me to modify my setup.py, which I did:
http://www.py2exe.org/index.cgi/TixSetup

However, the result is the same as above.
Inside my tcl folder, there are two other folders:
tcl8.5
tk8.5

My original code does use Tkinter:

import Tkinter,tkFileDialog, tkMessageBox #For allowing user to browse and save

#Give the user warning to select a file to open.
root = Tkinter.Tk()
root.withdraw()
tkMessageBox.showinfo(
"Attention!",
"Please select the CSV file you want to reformat."
)

# ======== Select a file for opening:
root = Tkinter.Tk()
root.withdraw()
filepathwayToOpen = tkFileDialog.askopenfilename(filetypes=[("CSV files","*.csv")],title='Select the csv file you want to convert.')
if filepathwayToOpen != None:
    print filepathwayToOpen

I did not include a root.mainloop() originally, but after reading it on some forum, I did. However, still no luck with the .exe.... Any help?

from distutils.core import setup
import py2exe
import sys

if len(sys.argv) == 1:
    sys.argv.append("py2exe")

setup( options = {"py2exe": {"compressed": 1, "optimize": 2, "ascii": 1, "bundle_files": 3}},
       zipfile = None,
       
       ##data_files = ['apple.jpg', 'cheese.jpg'],
       
       #Can use windows or console,replace my_file.py with py file you want to make exe off.
       #If not run in same folder give path /mydir/my_file.py
       windows = [{"script": 'my_file.py'}])

Or use gui2exe

Thanks, but the exe still doesn't work.

Here are the files that are now found in the dist folder (after using your setup.py or my setup.py + code from yours):

tcl (directory) - 7.08 MB
Reformatter.exe - 3625 KB
w9xopen.exe - 49 KB

I tried running GUI2EXE but I get this error:

import wx
ImportError: No module named wx

Any ideas? Do I need to place all of the GUI2Exe files inside my python directory?

Thanks for all of your continued help!

I was able to get GUI2Exe up and running and I must say that it is much more inuitive.

However, I'm running into another same issue.

The generated dist folder still has:

tcl (directory) - 7.08 MB
Reformatter.exe - 2256 KB
w9xopen.exe - 49 KB

However, I now have a log file that gets produced when I try to run the .exe. Maybe this will help? I really appreciate your support on this.

Traceback (most recent call last):
  File "<install zipextimporter>", line 1, in <module>
ImportError: No module named zipextimporter
Traceback (most recent call last):
  File "Reformatter.py", line 7, in <module>
ImportError: No module named csv

These are the import statements I have in my .py file, so I added them to the list in GUI2Exe:

import csv
import itertools #For transposing csv
import Tkinter,tkFileDialog, tkMessageBox #For allowing user to browse and save
import os
import time

Any ideas of what could be the issue? THANKS!

from distutils.core import setup
import py2exe
import sys

if len(sys.argv) == 1:
    sys.argv.append("py2exe")

setup( options = {"py2exe": {"compressed": 1, "optimize": 2, "ascii": 1, "bundle_files": 3}},
       zipfile = None,
       
       ##data_files = ['apple.jpg', 'cheese.jpg'],
       
       #Can use windows or console,replace my_file.py with py file you want to make exe off.
       #If not run in same folder give path /mydir/my_file.py
       windows = [{"script": 'my_file.py'}])

Or use gui2exe

I was searching solution for py2exe problem(the exe file didn't work for my simple gui program using tkinter).then i found ur code.I tried it using python2.7 idle ,reaching bout halfway raised following error:

running py2exe
*** searching for required modules ***
*** parsing results ***
creating python loader for extension '_tkinter' (C:\Python27\DLLs\_tkinter.pyd -> _tkinter.pyd)
creating python loader for extension '_ctypes' (C:\Python27\DLLs\_ctypes.pyd -> _ctypes.pyd)
creating python loader for extension 'select' (C:\Python27\DLLs\select.pyd -> select.pyd)
creating python loader for extension 'bz2' (C:\Python27\DLLs\bz2.pyd -> bz2.pyd)
*** finding dlls needed ***
*** create binaries ***
*** byte compile python files ***
writing byte-compilation script 'c:\docume~1\deewakar\locals~1\temp\tmpwd7pdi.py'
C:\Python27\pythonw.exe -OO c:\docume~1\deewakar\locals~1\temp\tmpwd7pdi.py

Traceback (most recent call last):
  File "C:\Python27\setup.py", line 14, in <module>
    windows = [{"script": 'ask.py'}])
  File "C:\Python27\lib\distutils\core.py", line 169, in setup
    raise SystemExit, "error: " + str(msg)
SystemExit: error: command 'C:\Python27\pythonw.exe' failed with exit status 1

any suggestions on that!

Insert the full path to the script instead of just the 'ask.py'.

Cheers and Happy coding

Insert the full path to the script instead of just the 'ask.py'.

Cheers and Happy coding

Insert the full path to the script instead of just the 'ask.py'.

Cheers and Happy coding

i really appreciated ur reply but still didn't work for me ,though displayed some more lines of processing.... still stuck with

Traceback (most recent call last):
  File "C:\Python27\setup.py", line 14, in <module>
    windows = [{"script": "C:\\Python27\\ask.py"}])
  File "C:\Python27\lib\distutils\core.py", line 169, in setup
    raise SystemExit, "error: " + str(msg)
SystemExit: error: command 'C:\Python27\pythonw.exe' failed with exit status 1

my program script is:

'C:/Python 27/python.exe'
from Tkinter import *
import tkCommonDialog
import Dialog
import tkMessageBox,tkFileDialog
import zipfile

var=bool

class Application(Frame):
    def __init__(self,master=None):
        Frame.__init__(self,master)
        self.grid()
        
        
        self.createWidgets()
        
        
    def confirm(self):
        class my_msg(Frame):
            def __init__(self,master=Application):
                Frame.__init__(self,master)
                
                self.pack(expand=False)
                self.createmsg()
            def createmsg(self):
                self.mssg=Label(self,text="Do you really want to exit?")
                self.mssg.grid(column=2,row=4)
                self.yesbutton=Button(self,text='Yes',relief='raised',command=self.kill)
                self.yesbutton.grid(column=2,row=6,sticky=S+E)
                self.nobutton=Button(self,text='No',relief='raised',command=root.destroy)
                self.nobutton.grid(column=3,row=6,sticky=N+W)
                
            def kill(self):
                root.destroy()
                app.master.destroy()
        root=Tk()
        msg1=my_msg(master=root)
        msg1.master.resizable(False,False)
        msg1.mainloop() 
        

    def createWidgets(self):
        
        self.quitButton = Button (self,text = 'Quit',activeforeground = 'red',
                                  relief = 'raised' )
        if var==True:
            self.quitButton["command"]=msg1.destroy()
        else:
            self.quitButton["command"]=self.confirm
        self.quitButton.grid()
        self._openf =Button(self,text ='extract file',relief = 'groove',command=self.openf)
        self._openf.grid()
       
    def openf(self):
        e=tkFileDialog.askopenfilename(title='extract file',defaultextension="zip,(.zip)",filetypes=[("ZIP COMPRESSED FILES",".zip")])
        
        
        f=zipfile.ZipFile(e)
        j=tkFileDialog.asksaveasfile(title='extract to:')
        f.extractall(j)
        
      
        
       
       
        
root = Tk()
app=Application(master=root)
app.master.title("The Zip EXtractor")
app.mainloop()

i just wanted to make my program executable on windows without python installed in it.

Can you post your full setup file?

Cheers and Happy coding.

here is my setup file

from distutils.core import setup
import py2exe
import sys
if len(sys.argv) == 1:
    sys.argv.append("py2exe")

setup( options = {"py2exe": {"compressed":1, "optimize": 2, "ascii":1,"includes": ["Tkinter"], "bundle_files": 3}},
       zipfile = None,
       
       
       windows = [{"script": "C:\\Python27\\ask.py"}])