cx_Freeze Fehler

Probleme bei der Installation?
GuardDog
User
Beiträge: 40
Registriert: Mittwoch 5. April 2017, 20:53
Wohnort: Hannover

cx_Freeze Fehler

Beitragvon GuardDog » Montag 29. Januar 2018, 23:09

Heyho liebe Python-Community,

ich habe einen kleinen Password-Generator in Python (3.6) geschrieben und dabei Tkinter verwendet. Nun wollte ich eine standalone-Version erstellen, wobei ich bei cx_Freeze gelandet bin. Mein Fehler sowie der Code der setup.py und der PasswordGen.py stehen unten.

Post Scriptum: Ich weiß, dass ich eigentlich Klassen nutzen sollte, hatte aber noch keine Zeit mich da reinzulesen :mrgreen:

Danke im Voraus.

Der Fehler:
Bild

setup.py:
  1. import os
  2. from cx_Freeze import setup, Executable
  3.  
  4. os.environ['TCL_LIBRARY'] = 'C:\\Users\\Tim Piglowski\\AppData\\Local\\Programs\\Python\\Python36-32\\tcl\\tcl8.6'
  5. os.environ['TK_LIBRARY'] = 'C:\\Users\\Tim Piglowski\\AppData\\Local\\Programs\\Python\\Python36-32\\tcltk8.6'
  6.  
  7. # Dependencies are automatically detected, but it might need
  8. # fine tuning.
  9. buildOptions = dict(
  10.     packages = ['random', 'pyperclip'],
  11.     excludes = [],
  12.     include_files=['PWG.ico', 'C:\\Users\\Tim Piglowski\\AppData\\Local\\Programs\\Python\\Python36-32\\DLLs\\tcl86t.dll', 'C:\\Users\\Tim Piglowski\\AppData\\Local\\Programs\\Python\\Python36-32\\DLLs\\tk86t.dll']
  13. )
  14.  
  15. import sys
  16. base = 'Win32GUI' if sys.platform=='win32' else None
  17.  
  18. executables = [
  19.     Executable('PasswordGen.py', base=base)
  20. ]
  21.  
  22. setup(name='PasswordGenerator',
  23.       version = '1.0',
  24.       description = 'A simple, python-based, password generator',
  25.       options = dict(build_exe = buildOptions),
  26.       executables = executables)


PasswordGenerator.py
  1. from tkinter import *
  2. import random, pyperclip
  3.  
  4. chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!?.:,;-_#+*"
  5. var_width_big = 50
  6. var_width_small = 20
  7. var_width_extra = int(var_width_big + var_width_small  + var_width_small - 7)
  8.  
  9. def generate():
  10.     length = int(length_entry.get())
  11.     password = ""
  12.     if length <51:
  13.         for c in range(length):
  14.             password += random.choice(chars)
  15.         output_entry.delete(0, END)
  16.         output_entry.insert(END, password)
  17.  
  18. def clearall():
  19.     length_entry.delete(0, END)
  20.     output_entry.delete(0, END)
  21.     name_entry.delete(0, END)
  22.  
  23. def clipboard():
  24.     print(output_entry.get)
  25.     pyperclip.copy(name_entry.get() + " - " + output_entry.get() + "\n")
  26.     pyperclip.paste()
  27.  
  28. def addlist():
  29.     textfile = open("list.txt", "a")
  30.     textfile.write(name_entry.get() + " - " + output_entry.get() + "\n")
  31.     textfile.close
  32.  
  33. root = Tk()
  34. root.title("Password Generator")
  35. root.resizable(0,0)
  36. root.iconbitmap('PWG.ico')
  37.  
  38. length_lbl = Label(root, width=var_width_small - 7, text="Length (1-50)")
  39. output_lbl = Label(root, width=var_width_small -7, text="Your Password")
  40. name_lbl = Label(root, width=var_width_small -7, text="Related account")
  41. length_entry = Entry(root, width=var_width_big, relief="solid", borderwidth=1)
  42. output_entry = Entry(root, width=var_width_big, relief="solid", borderwidth=1)
  43. name_entry = Entry(root, width=var_width_big, relief="solid", borderwidth=1)
  44. clear_btn = Button(root, width=var_width_small, relief="solid", borderwidth=1, text="clear", command=clearall)
  45. copy_btn = Button(root, width=var_width_small, relief="solid", borderwidth=1, text="copy", command=clipboard)
  46. list_btn = Button(root, width=var_width_small, relief="solid", borderwidth=1, text="store in list", command=addlist)
  47. generate_btn = Button(root, width=var_width_extra, relief="solid", borderwidth=1, text="GENERATE!", command=generate)
  48.  
  49. length_lbl.grid(row=1, column=1, pady=1, padx=1)
  50. output_lbl.grid(row=2, column=1, pady=1, padx=1)
  51. name_lbl.grid(row=3, column=1, pady=1, padx=1)
  52. length_entry.grid(row=1, column=2, pady=1, padx=1)
  53. output_entry.grid(row=2, column=2, pady=1, padx=1)
  54. name_entry.grid(row=3, column=2, pady=1, padx=1)
  55. clear_btn.grid(row=1, column=3, pady=1, padx=1)
  56. copy_btn.grid(row=2, column=3, pady=1, padx=1)
  57. list_btn.grid(row=3, column=3, pady=1, padx=1)
  58. generate_btn.grid(row=4, column=1, columnspan=3)
  59. root.mainloop()
Benutzeravatar
__deets__
User
Beiträge: 2137
Registriert: Mittwoch 14. Oktober 2015, 14:29

Re: cx_Freeze Fehler

Beitragvon __deets__ » Montag 29. Januar 2018, 23:48

Was mich wundert sind deine Angaben von Pfaden für die TCL/TK Geschichten. Das sollte nicht nötig sein, und ist schlimmstenfalls Ursache.
GuardDog
User
Beiträge: 40
Registriert: Mittwoch 5. April 2017, 20:53
Wohnort: Hannover

Re: cx_Freeze Fehler

Beitragvon GuardDog » Montag 29. Januar 2018, 23:51

Ich hatte es so gelesen, als ich auf der Suche nach einer Möglichkeit war TK einzubinden. Ich probier's morgen einmal ohne die Angabe aus. Danke aber schon mal :D
GuardDog
User
Beiträge: 40
Registriert: Mittwoch 5. April 2017, 20:53
Wohnort: Hannover

Re: cx_Freeze Fehler

Beitragvon GuardDog » Dienstag 30. Januar 2018, 08:11

Ich habe es jetzt ohne die Angaben versucht. Nun bekomme ich folgenden Fehler:

C:\Users\Tim Piglowski\Desktop>python setup.py build

running build
running build_exe
Traceback (most recent call last):
File "setup.py", line 26, in <module>
executables = executables)
File "C:\Users\Tim Piglowski\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cx_Freeze\dist.py", line 349, in setup
distutils.core.setup(**attrs)
File "C:\Users\Tim Piglowski\AppData\Local\Programs\Python\Python36-32\lib\distutils\core.py", line 148, in setup
dist.run_commands()
File "C:\Users\Tim Piglowski\AppData\Local\Programs\Python\Python36-32\lib\distutils\dist.py", line 955, in run_commands
self.run_command(cmd)
File "C:\Users\Tim Piglowski\AppData\Local\Programs\Python\Python36-32\lib\distutils\dist.py", line 974, in run_command
cmd_obj.run()
File "C:\Users\Tim Piglowski\AppData\Local\Programs\Python\Python36-32\lib\distutils\command\build.py", line 135, in run
self.run_command(cmd_name)
File "C:\Users\Tim Piglowski\AppData\Local\Programs\Python\Python36-32\lib\distutils\cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "C:\Users\Tim Piglowski\AppData\Local\Programs\Python\Python36-32\lib\distutils\dist.py", line 974, in run_command
cmd_obj.run()
File "C:\Users\Tim Piglowski\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cx_Freeze\dist.py", line 219, in run
freezer.Freeze()
File "C:\Users\Tim Piglowski\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cx_Freeze\freezer.py", line 618, in Freeze
self._FreezeExecutable(executable)
File "C:\Users\Tim Piglowski\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cx_Freeze\freezer.py", line 201, in _FreezeExecutable
finder.IncludeFile(exe.script, exe.moduleName)
File "C:\Users\Tim Piglowski\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cx_Freeze\finder.py", line 637, in IncludeFile
deferredImports)
File "C:\Users\Tim Piglowski\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cx_Freeze\finder.py", line 475, in _LoadModule
self._ScanCode(module.code, module, deferredImports)
File "C:\Users\Tim Piglowski\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cx_Freeze\finder.py", line 565, in _ScanCode
module, relativeImportIndex)
File "C:\Users\Tim Piglowski\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cx_Freeze\finder.py", line 311, in _ImportModule
deferredImports, namespace = namespace)
File "C:\Users\Tim Piglowski\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cx_Freeze\finder.py", line 404, in _InternalImportModule
parentModule, namespace)
File "C:\Users\Tim Piglowski\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cx_Freeze\finder.py", line 417, in _LoadModule
namespace)
File "C:\Users\Tim Piglowski\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cx_Freeze\finder.py", line 486, in _LoadPackage
self._LoadModule(name, fp, path, info, deferredImports, parent)
File "C:\Users\Tim Piglowski\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cx_Freeze\finder.py", line 464, in _LoadModule
self._RunHook("load", module.name, module)
File "C:\Users\Tim Piglowski\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cx_Freeze\finder.py", line 537, in _RunHook
method(self, *args)
File "C:\Users\Tim Piglowski\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cx_Freeze\hooks.py", line 615, in load_tkinter
tclSourceDir = os.environ["TCL_LIBRARY"]
File "C:\Users\Tim Piglowski\AppData\Local\Programs\Python\Python36-32\lib\os.py", line 669, in __getitem__
raise KeyError(key) from None
KeyError: 'TCL_LIBRARY'

C:\Users\Tim Piglowski\Desktop>python setup.py build
running build
running build_exe
Traceback (most recent call last):
File "setup.py", line 23, in <module>
executables = executables)
File "C:\Users\Tim Piglowski\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cx_Freeze\dist.py", line 349, in setup
distutils.core.setup(**attrs)
File "C:\Users\Tim Piglowski\AppData\Local\Programs\Python\Python36-32\lib\distutils\core.py", line 148, in setup
dist.run_commands()
File "C:\Users\Tim Piglowski\AppData\Local\Programs\Python\Python36-32\lib\distutils\dist.py", line 955, in run_commands
self.run_command(cmd)
File "C:\Users\Tim Piglowski\AppData\Local\Programs\Python\Python36-32\lib\distutils\dist.py", line 974, in run_command
cmd_obj.run()
File "C:\Users\Tim Piglowski\AppData\Local\Programs\Python\Python36-32\lib\distutils\command\build.py", line 135, in run
self.run_command(cmd_name)
File "C:\Users\Tim Piglowski\AppData\Local\Programs\Python\Python36-32\lib\distutils\cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "C:\Users\Tim Piglowski\AppData\Local\Programs\Python\Python36-32\lib\distutils\dist.py", line 974, in run_command
cmd_obj.run()
File "C:\Users\Tim Piglowski\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cx_Freeze\dist.py", line 219, in run
freezer.Freeze()
File "C:\Users\Tim Piglowski\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cx_Freeze\freezer.py", line 618, in Freeze
self._FreezeExecutable(executable)
File "C:\Users\Tim Piglowski\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cx_Freeze\freezer.py", line 201, in _FreezeExecutable
finder.IncludeFile(exe.script, exe.moduleName)
File "C:\Users\Tim Piglowski\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cx_Freeze\finder.py", line 637, in IncludeFile
deferredImports)
File "C:\Users\Tim Piglowski\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cx_Freeze\finder.py", line 475, in _LoadModule
self._ScanCode(module.code, module, deferredImports)
File "C:\Users\Tim Piglowski\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cx_Freeze\finder.py", line 565, in _ScanCode
module, relativeImportIndex)
File "C:\Users\Tim Piglowski\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cx_Freeze\finder.py", line 311, in _ImportModule
deferredImports, namespace = namespace)
File "C:\Users\Tim Piglowski\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cx_Freeze\finder.py", line 404, in _InternalImportModule
parentModule, namespace)
File "C:\Users\Tim Piglowski\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cx_Freeze\finder.py", line 417, in _LoadModule
namespace)
File "C:\Users\Tim Piglowski\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cx_Freeze\finder.py", line 486, in _LoadPackage
self._LoadModule(name, fp, path, info, deferredImports, parent)
File "C:\Users\Tim Piglowski\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cx_Freeze\finder.py", line 464, in _LoadModule
self._RunHook("load", module.name, module)
File "C:\Users\Tim Piglowski\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cx_Freeze\finder.py", line 537, in _RunHook
method(self, *args)
File "C:\Users\Tim Piglowski\AppData\Local\Programs\Python\Python36-32\lib\site-packages\cx_Freeze\hooks.py", line 615, in load_tkinter
tclSourceDir = os.environ["TCL_LIBRARY"]
File "C:\Users\Tim Piglowski\AppData\Local\Programs\Python\Python36-32\lib\os.py", line 669, in __getitem__
raise KeyError(key) from None
KeyError: 'TCL_LIBRARY'
Benutzeravatar
__deets__
User
Beiträge: 2137
Registriert: Mittwoch 14. Oktober 2015, 14:29

Re: cx_Freeze Fehler

Beitragvon __deets__ » Dienstag 30. Januar 2018, 08:43

Ah. Doof. Ich würde es einfach mal mit der Alternative py2exe probieren. - vielleicht ist die weniger bockig.
Benutzeravatar
_Inducer_
User
Beiträge: 2
Registriert: Donnerstag 26. Oktober 2017, 07:37

Re: cx_Freeze Fehler

Beitragvon _Inducer_ » Freitag 9. Februar 2018, 13:24

Bei mir funktioniert es mit dieser Setup.py.

  1. import cx_Freeze
  2. import sys
  3. import os
  4.  
  5. base = None
  6. os.environ["TCL_LIBRARY"] = r"C:\Users\Tim Piglowski\AppData\Local\Programs\Python\Python36-32\tcl\tcl8.6"
  7. os.environ["TK_LIBRARY"] = r"C:\Users\Tim Piglowski\AppData\Local\Programs\Python\Python36-32\tcl\tk8.6"
  8.  
  9. # GUI applications require a different base on Windows (the default is for a
  10. # console application).
  11. if sys.platform == "win32":
  12.     base = "Win32GUI"
  13. #if sys.platform == "win32":
  14. #    base = "console"
  15.  
  16. executables = [cx_Freeze.Executable("PasswordGen.py", base = base)] #, icon="Icon.ico")]
  17.  
  18. cx_Freeze.setup(
  19.     name="PasswordGenerator",
  20.     options = {"build_exe": {"packages":["tkinter"], "include_files":[r"C:\Users\Tim Piglowski\AppData\Local\Programs\Python\Python36-32\DLLs\tcl86t.dll",
  21.                                                                       r"C:\Users\Tim Piglowski\AppData\Local\Programs\Python\Python36-32\DLLs\tk86t.dll",
  22.                                                                       "PWG.ico"]}},  
  23.     version = "1.0",
  24.     description = "A simple, python-based, password generator",
  25.     executables = executables
  26.     )

Wer ist online?

Mitglieder in diesem Forum: 0 Mitglieder