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'.
Related
I made an app that uses tkinter and tkinterdnd moudles. It works completely fine when I launch it as a script, however when I try to make and executable file from it and laucnh it, foloowing error ocures:
Traceback (most recent call last):
File "TkinterDnD2\TkinterDnD.py", line 53, in _require
_tkinter.TclError: can't find package tkdnd
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "IxcomGUI.py", line 128, in <module>
File "IxcomGUI.py", line 11, in __init__
File "TkinterDnD2\TkinterDnD.py", line 285, in __init__
File "TkinterDnD2\TkinterDnD.py", line 55, in _require
RuntimeError: Unable to load tkdnd library.
[14512] Failed to execute script 'IxcomGUI' due to unhandled exception!
I tried following:
Installed tkinterdnd2 with pip install and built with pyinstaller myscript.py.
Manually installed tkinterdnd2 module as shown in this video https://www.youtube.com/watch?v=JIy0QjwQBl0&t=605s&ab_channel=RamonWilliams and built with pyinstaller myscript.py
Repeated previous step, but added this thing https://github.com/pmgagne/tkinterdnd2/blob/master/hook-tkinterdnd2.py
Tried to implicitly tell pyinstaller path to tkdnd module with specifying path to the module with --paths flag.
All this attempts led to error bellow. Does anyone know some kind of solution?
The issue here is that Drag n Drop requires two components: the TCL libraries and the Tkinter interface to them. I install both manually to config my environment. (See my answer to How to Install and Use TkDnD with Python Tkinter on OSX?). I know someone packaged something on PyPI for the TkinterDnD2, but I haven't looked into it.
I have a project which uses TkinterDnD2. I build it with PyInstaller and see the same error you see (more or less). Running PyInstaller with the --onedir option (rather than the --onefile option), I saw that tkdnd2.8 was missing from my dist directory.
To rectify this, on Windows, I added
--add-binary "C:/Python/Python38-32/tcl/tkdnd2.8;tkdnd2.8"
to the PyInstaller command line, and that did the trick. I can now build a --onefile executable, and it runs without error.
Apparently it was unnexpectedly easy to fix this issue. All you need to is to get to the <YourPath>\Python39\tcl directory and find tkdnd2.8 directory, and move it to the tcl8.6 directory. I have also renamed it to just tkdnd, however I don't know whether it's necessary.
Here is the original link that saved my day: http://pyinstaller.47505.x6.nabble.com/tkinter-TclError-can-t-find-package-tkdnd-td2330.html
I'm using tkinterdnd2 installed from pip, and not TkinterDnD.
What really worked for me was this flag:
--add-data "C:/Users/myName/AppData/Local/Packages/PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0/LocalCache/local-packages/Python39/site-packages/tkinterdnd2;tkinterdnd2"
It expects tkdnd to be a folder inside tkinterdnd2. Just using additional-hooks/hidden import on tkinterdnd2 and tkdnd did now preserve that subfolder structure.
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 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
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.
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.