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
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.
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
Related
I'm operating on a windows 7 machine but because I don't have admin rights, I needed to use a portable version of python.
I'm following these two tutorials:
https://kivy.org/docs/installation/installation-windows.html#
https://github.com/kivy/kivy-designer
I was able to get kivy installed to my portable python path and I'm running into trouble with the 2nd tutorials
garden install filebrowser
I checked my installed modules and it says that I have kivy-garden:
['argh==0.26.1', 'docutils==0.12', 'gitdb==0.6.4', 'gitpython==1.0.1', 'jedi==0.9.0', 'kivy-garden==0.1.4', 'kivy.deps.glew== 0.1.4', 'kivy.deps.gstreamer==0.1.5', 'kivy.deps.sdl2==0.1.12', 'kivy==1.9.1', 'lxml==3.3.4', 'matplotlib==1.3.1', 'numpy==1.8.1', 'pandas==0.11.0', 'pathtools==0.1.2', 'pil==1.1.7', 'pip==8.0.2', 'py2exe==0.6.9', 'pycairo==1.8.10', 'pygame==1.9.1','pygments==2.1', 'pygobject==2.28.3', 'pygoocanvas==0.14.2', 'pygtk==2.24.0', 'pygtksourceview==2.10.1', 'pyodbc==3.0.7', 'pyparsing==2.0.1', 'pypiwin32==219', 'pyrsvg==2.32.1', 'pyserial==2.7', 'pywin32==218', 'pyyaml==3.11', 'requests==2.9.1', 'scipy==0.13.3', 'setuptools==19.4', 'six==1.10.0', 'smmap==0.9.0', 'watchdog==0.8.3', 'wheel==0.26.0']
I tried to launch the designer's main.py without the file browser and I get the following error:
Traceback (most recent call last):
File "C:\Sources\Portable_Python_2.7.6.1\kivy-designer-master\main.py", line 2, in <module>
from designer.app import DesignerApp
File "C:\Sources\Portable_Python_2.7.6.1\kivy-designer-master\designer\app.py", line 28, in <module>
from kivy.garden.filebrowser import FileBrowser
ImportError: No module named filebrowser
Which it appears I cannot do unless I install the filebrowser.
Has anyone run into this before? I don't care if I don't have a file browser, I really just want the Kivy Designer to work because I'm still learning Python GUI modeling and having a designer would make it so much easier. Many of the tutorials I've looked at talk about using the Kivy.bat, but I have searched everywhere and when you using the installation on windows, a Kivy.bat is never created.
I'm currently trying to package a Tkinter app into a .exe file using py2exe. The packaging works fine, and up until a point, the program functions. When I call a certain function, though, running the .exe file logs the following error:
Exception in Tkinter callback
Traceback (most recent call last):
File "Tkinter.pyc", line 1532, in __call__
File "/Users/Gordon/Gordon's Files/AutoFormatter/lib\formatterApp.py", line 58, in go
File "formatter.pyc", line 72, in take
File "docx\api.pyc", line 25, in Document
File "docx\opc\package.pyc", line 116, in open
File "docx\opc\pkgreader.pyc", line 32, in from_file
File "docx\opc\phys_pkg.pyc", line 31, in __new__
PackageNotFoundError: Package not found at 'C:\Users\Gordon\Gordon's Files\AutoFormatter\dist\library.zip\docx\templates\default.docx'
Upon originally running py2exe, I checked the \docx\ folder and found that py2exe hadn't actually copied over the \templates\ folder. After manually unzipping the library.zip, adding in the \templates\ folder in the right place, and then manually re-zipping, however, I get the same error.
My setup.py is as follows:
from distutils.core import setup
import py2exe
setup(
windows=[{'script': 'AutoFormatter.py'}],
options={
'py2exe':
{
'includes': ['lxml.etree', 'lxml._elementpath', 'gzip', 'docx'],
}
}
)
I'm running the program on a Windows 7 computer using Python 2.7.8 and py2exe 0.6.9.
This might be too late but I have been having the same troubles as well. I don't know if python-docx was made to be compiled into a single executable yet, none the less I have found solution.
I am on pyinstaller with python2.7, essentially the same thing. I hope that you are freezing into one directory rather than one file. This won't work if you're freezing to one file
Download this here(Mediafire link)
Place it in
C:\Users\Gordon\Gordon's Files\AutoFormatter\dist\library.zip\docx\templates\default.docx
basically wherever your .exe is in.
Hopefully that does the trick
Based off of me scouring through my own directories and the docx module, when you create a document:
doc = Document()
doc.save('hello.docx')
It pulls a template for you to use, if you do not create your own, it will use the default template offered by python-docx itself.
Don't quote me on this, but I believe python-docx looks through its own directories to find the default.docx template when executing it through python.
Since we compiled the script, the path changed to the directory in which the .exe is placed, however pyinstaller (or in your case py2exe) does not include the template with the dist folder, and this creates the PackageNotFoundError
I downloaded py2exe for python 2.6. I include this bit of code:
from distutils.core import setup
import py2exe
setup(console=['move2.py'])
'move2.py' being my first script. This code is from my second script as said in the video. I opened cmd and typed 'movesetup.py py2exe' and pressed enter. Instead it came up with a error message:
Traceback (most recent call last):
File "C:\Users\User\Desktop\move.py", line 1, in (module)
from distutlis.core import setup
ImportError: No module named distutlis.core
I downloaded py2exe right and I downloaded the right one for Python 2.6. Here is the website that I found how to change .py to .exe. Is he right? I also tried cx_freeze too but that didn't work either. https://www.youtube.com/watch?v=HR483VkOvkE
You have a typo: distutlis
Change to distutils, and read the error next time. ;)
While trying to use py2exe to create an executable for my GUI program, I got the following error:
Traceback (most recent call last):
File "dopy.py", line 139, in <module>
File "Tix.pyc", line 225, in __init__
_tkinter.TclError: can't find package Tix
My program imports Tix, but py2exe does not package it.
I could not find any solution online that worked, but the closest was http://www.py2exe.org/index.cgi/TixSetup.
Unfortunately, changing the data_files to my Tix path (My Tix8.4.3 instead of the old Tix8.1) does not work either.
My program executable is unable to start without Tix, and py2exe does not seem to want to include it.
Looking in the 'dist' folder that py2exe made, I noticed that there is a tcl folder, and inside it is included a 'tcl8.5' folder and a 'tk8.5' folder, but no Tix folder. These folders were identical ones under my 'Python/tcl/' folder.
Simply copying the 'tix8.4.3' folder into the 'dist/tcl/' folder will include the Tix DLLs and package files, and now my program works!
Use py2exe option packages to help py2exe find the package 'Tix'.
I'm working on making a py2exe version of my app. Py2exe fails at copying some
modules in. My original app loads .png files fine, but the exe version does not:
Traceback (most recent call last):
File "app.py", line 1, in <module>
from gui.main import run
File "gui\main.pyc", line 14, in <module>
File "gui\controllers.pyc", line 10, in <module>
File "gui\utils\images.pyc", line 78, in <module>
☺
File "gui\utils\images.pyc", line 70, in GTK_get_pixbuf
☺§☺▲☻
File "gui\utils\images.pyc", line 38, in PIL_to_pixbuf
gobject.GError: Image type 'png' is not supported
Any idea what I should force py2exe to include?
This is a known problem with PIL and py2exe
PIL (python image library) imports its plugins dynamically which py2exe doesn't pick up on, so it doesn't include the plugins in the .exe file.
The fix (hopefully!) is to import the drivers explicitly like this in one of your .py files
import Image
import PngImagePlugin
Image._initialized=2
That will mean that py2exe will definitely include the plugin. The Image._initialized bit stops PIL scanning for more plugins.
Here are the docs from the py2exe wiki explaining this in full
What platform is this?
Lately I think they improved the png support on windows,
so the version of pygtk you're using is pertinent also.
http://aruiz.typepad.com/siliconisland/2008/02/goodbye-zlib-li.html
Make sure you bundle the loaders when you install your application. Py2exe won't know about these, but they are a needed part of GTK, and live where the rest of the GTK "data" files live.
From http://unpythonic.blogspot.com/2007/07/pygtk-py2exe-and-inno-setup-for-single.html
It is not sufficient to just make
py2exe pull in the GTK DLLs for
packaging (which it does pretty
successfully). GTK also requires a
number of data files which include
themes, translations etc. These will
need to be manually copied into the
dist directory so that the application
can find them when being run.
If you look inside your GTK runtime
directory (usually something like
c:\GTK) you will find the
directories: share, etc, lib. You will
need to copy all of these into the
dist directory after running py2exe.
Copyright retained.