How to create .exe from python script with modules and dependent files

3.8k views Asked by At

I want to create an executable .exe file from my python script. I have tried many tutorials and ways explained on the web to do this. I have tried py2exe pyInstaller but I couldnt create a working executable file. I'm using Enthought Canopy as my programming environment. The modules imported in the code are as follows:

import Tkinter as tk
from Tkinter import Text
from PIL import ImageTk, Image
import pyttsx
import pickle

I'm using an object from a file that I have created by pickle so I need them too. Lets say I have 2 files named a.fil b.fil

When I run the .exe file it instantly show a command prompt and closes it directly.

Traceback (most recent call last):
    File "code.py", line 4 in <module>
    File "Tkinter.pyc", line 38 in <module>
    File "FixTk.pyc", line 65 in <module>
    File "_tkinter.pyc", line 12 in <module>
    File "_tkinter.pyc", line 10 in _load
Import Error: DLL load failed : %1 is not a valid win32 application
2

There are 2 answers

1
Alex Ivanov On

There's only py2exe. Just read the manual. py2exe will never copy all DLLs because it's illegal since the window stuff is the Intellectual Property of Microsoft and copying it violates the copyright law. If you need DLLs copy them yourself. If you don't know which ones use Dependency Walker.

0
Dukk On

Try changing the settings for py2exe. Or, read the manual. py2exe can't copy all DLLs because, like Alex Ivanov said:

py2exe will never copy all DLLs because it's illegal since the window stuff is the Intellectual Property of Microsoft and copying it violates the copyright law. If you need DLLs copy them yourself