Im using Python 3.6 and I wrote a script in which the user enters data through tkinter GUI
and it gets then printed along with some extra text into a WORD doc.
All works fine in my Wing IDE but once it comes to converting it to .exe
it either shows mistakes when I use py2exe
/ cx_Freeze
or just opens and instantly closes the window when I convert it with pyinstaller
.
When I try to convert the script containing standad libraries and tkinter it works perfectly fine. But once I include docx
it just doesnt want to work for some reason. As I am aware now the Pyinstaller does not want to work with docx
. Is there any other ways I can convert my script containing docx
into .exe
?
Also, Im pretty new to programming. Thanks in advance.
Here's a short example:
from tkinter import *
from docx import Document
from docx.shared import Inches
document = Document('CRS-example.docx')
def Generate(event):
document.add_paragraph('Hello World')
document.save('TESTING.docx')
root = Tk()
frame = Frame(root)
frame.pack()
generate = Button(frame, text = 'Generate')
generate.bind('<Button-1>', Generate)
generate.pack()
root.mainloop()
On top of that the cx_Freeze gives me such list of mistakes:
Traceback (most recent call last):
File "setupcx.py", line 18, in <module>
executables = [Executable("tkinter_test.py", base = base)])
File "C:\Development\Python\lib\site-packages\cx_Freeze\dist.py", line 349, in setup
distutils.core.setup(**attrs)
File "C:\Development\Python\lib\distutils\core.py", line 148, in setup
dist.run_commands()
File "C:\Development\Python\lib\distutils\dist.py", line 955, in run_commands
self.run_command(cmd)
File "C:\Development\Python\lib\distutils\dist.py", line 974, in run_command
cmd_obj.run()
File "C:\Development\Python\lib\distutils\command\build.py", line 135, in run
self.run_command(cmd_name)
File "C:\Development\Python\lib\distutils\cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "C:\Development\Python\lib\distutils\dist.py", line 974, in run_command
cmd_obj.run()
File "C:\Development\Python\lib\site-packages\cx_Freeze\dist.py", line 219, in run
freezer.Freeze()
File "C:\Development\Python\lib\site-packages\cx_Freeze\freezer.py", line 616, in Freeze
self.finder = self._GetModuleFinder()
File "C:\Development\Python\lib\site-packages\cx_Freeze\freezer.py", line 340, in _GetModuleFinder
finder.IncludeModule(name)
File "C:\Development\Python\lib\site-packages\cx_Freeze\finder.py", line 651, in IncludeModule
namespace = namespace)
File "C:\Development\Python\lib\site-packages\cx_Freeze\finder.py", line 311, in _ImportModule
deferredImports, namespace = namespace)
File "C:\Development\Python\lib\site-packages\cx_Freeze\finder.py", line 404, in _InternalImportModule
parentModule, namespace)
File "C:\Development\Python\lib\site-packages\cx_Freeze\finder.py", line 417, in _LoadModule
namespace)
File "C:\Development\Python\lib\site-packages\cx_Freeze\finder.py", line 486, in _LoadPackage
self._LoadModule(name, fp, path, info, deferredImports, parent)
File "C:\Development\Python\lib\site-packages\cx_Freeze\finder.py", line 464, in _LoadModule
self._RunHook("load", module.name, module)
File "C:\Development\Python\lib\site-packages\cx_Freeze\finder.py", line 537, in _RunHook
method(self, *args)
File "C:\Development\Python\lib\site-packages\cx_Freeze\hooks.py", line 615, in load_tkinter
tclSourceDir = os.environ["TCL_LIBRARY"]
File "C:\Development\Python\lib\os.py", line 669, in __getitem__
raise KeyError(key) from None
KeyError: 'TCL_LIBRARY'
This is also my cx_Freeze setup.py in which I am getting above errors:
import sys
from cx_Freeze import setup, Executable
build_exe_options = {"includes": ["tkinter"]}
base = None
if sys.platform == "win32":
base = "Win32GUI"
setup(
name = "simple_Tkinter",
version = "0.1",
description = "Sample cx_Freeze Tkinter script",
options = {"build_exe": build_exe_options},
executables = [Executable("tkinter_test.py", base = base)])