py2exe'd version of GTK app can't read png files - python

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.

Related

py2exe PackageNotFoundError

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

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

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

Py2exe cannot be convert python script to Windows executables

I want to make the python script into Windows executable with py2exe. I did not miss MSVCP90.dll and the Feiwings.py(the file that I use for transforming) and setup.py are under the same path. Doing those things under command window, everything works fine, the last lines of the traceback here are:
**binary dependencies****
your executable(s) also depend on these dlls which are not included. You may or may not need to distribute them.
Make sure you have the license if you distribute any of them, and make sure you don't distribute files belonging to the operating system.
USER32.dll -C:\WINDOWS\system32\USER32.dll
SHELL32.dll -C:\WINDOWS\system32\SHELL32.dll
ADVAPI32.dll -C:\WINDOWS\system32\ADVAPI32.dll
WS2_32.dll -C:\WINDOWS\system32\WS2_32.dll
GDI32.dll -C:\WINDOWS\system32\GDI32.dll
KERNEL32.dll -C:\WINDOWS\system32\KERNEL32.dll
The setup.py has the content like this:
from distutils.core import setup
import py2exe
setup(console=['D:\python\Feiwings.py'])
When I cd the path to dist directory, it got an error.
Traceback (most recent call last):
File "Feiwings.py", line 2, in <module>
File "PySide\__init__.pyc", line 45, in <module>
File "PySide\__init__.pyc", line 43, in _setupQtDirectories
UnboundLocalError: local variable 'path' referenced before assignment
Thanks in advance!
It seems something is wrong in your PySide distribution. From the traceback, it shows a problem in the second line of your Feiwings program. In this line there is probably an import statement where you import something from PySide, right?
Apart from the py2exe problem, are you able to execute your code normally without raising the same error?
If so, I would guess that you should include other packages dependencies (eg.: PySide) in your setup, something similar to:
setup(packages=['PySide'],
console=['D:\python\Feiwings.py'])
Hope it helps!
Check the variable 'path' in the program. It seems not a error of Pyside(assuming that you have properly installed Pyside) but the way you have used the variable 'path'. Having a look at the error it seems you have used variable 'path' before assigning it any value.

Pygame breaks outside of Pydev.

Me and a team of friends created this game which I am now trying to run in linux,
We developed it using python 2.7 and Pygame in windows using Aptana studio and the code fully work when running through there.
When downloading it to linux It wouldn't load saying that it could not find files. I then tried running it via CMD in windows and there is the same error.
the error so far is
Traceback (most recent call last):
File "/home/user/Desktop/Raspberroids/mainmenu.py", line 144, in <module>
showMenu()
File "/home/user/Desktop/Raspberroids/mainmenu.py", line 107, in showMenu
menu.init(['Start','About','Quit'], surface)
File "/home/user/Desktop/Raspberroids/mainmenu.py", line 52, in init
self.create_strukture()
File "/home/user/Desktop/Raspberroids/mainmenu.py", line 73, in create_strukture
self.font = pygame.font.Font(self.font_path, self.fontsize)
IOError: unable to read font filename
And the source is at:
https://github.com/ryanteck/RasPiThon/tree/master/Raspberroids/Source%20Code
Happens on both 2.7 and 2.6
Can anyone help?
Your font path data/coders_crux/coders_crux.ttf is relative.
When you start your game from another directory than your source directory, pygame can't find the font.
A simple fix is to add the following lines to the top of your script (mainmenu.py):
import os
os.chdir(os.path.dirname(os.path.realpath(__file__)))
os.path.realpath(\__file__) will get the path to your script, and with os.chdir and os.path.dirname you change the current working directory to the directory of your script.
This way, the relative paths you use will work.
PyDev sets working directory and PYTHONPATH variable for your programs. It can also set console encoding to something different than OS defaults.
Add a print self.font_path statement before creating your Font object and see if path is OK. If it's relative path, you could also use os.path.abspath (see os.path docs for details) to get better understanding of what's going on.

py2exe can't find package Tix

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'.

Categories