cx_Freeze Fehler

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

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:

Code: Alles auswählen

import os
from cx_Freeze import setup, Executable

os.environ['TCL_LIBRARY'] = 'C:\\Users\\Tim Piglowski\\AppData\\Local\\Programs\\Python\\Python36-32\\tcl\\tcl8.6'
os.environ['TK_LIBRARY'] = 'C:\\Users\\Tim Piglowski\\AppData\\Local\\Programs\\Python\\Python36-32\\tcltk8.6'

# Dependencies are automatically detected, but it might need
# fine tuning.
buildOptions = dict(
    packages = ['random', 'pyperclip'],
    excludes = [],
    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']
)

import sys
base = 'Win32GUI' if sys.platform=='win32' else None

executables = [
    Executable('PasswordGen.py', base=base)
]

setup(name='PasswordGenerator',
      version = '1.0',
      description = 'A simple, python-based, password generator',
      options = dict(build_exe = buildOptions),
      executables = executables)
PasswordGenerator.py

Code: Alles auswählen

from tkinter import *
import random, pyperclip

chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!?.:,;-_#+*"
var_width_big = 50
var_width_small = 20
var_width_extra = int(var_width_big + var_width_small  + var_width_small - 7)

def generate():
    length = int(length_entry.get())
    password = ""
    if length <51:
        for c in range(length):
            password += random.choice(chars)
        output_entry.delete(0, END)
        output_entry.insert(END, password)

def clearall():
    length_entry.delete(0, END)
    output_entry.delete(0, END)
    name_entry.delete(0, END)

def clipboard():
    print(output_entry.get)
    pyperclip.copy(name_entry.get() + " - " + output_entry.get() + "\n")
    pyperclip.paste()

def addlist():
    textfile = open("list.txt", "a")
    textfile.write(name_entry.get() + " - " + output_entry.get() + "\n")
    textfile.close

root = Tk()
root.title("Password Generator")
root.resizable(0,0)
root.iconbitmap('PWG.ico')

length_lbl = Label(root, width=var_width_small - 7, text="Length (1-50)")
output_lbl = Label(root, width=var_width_small -7, text="Your Password")
name_lbl = Label(root, width=var_width_small -7, text="Related account")
length_entry = Entry(root, width=var_width_big, relief="solid", borderwidth=1)
output_entry = Entry(root, width=var_width_big, relief="solid", borderwidth=1)
name_entry = Entry(root, width=var_width_big, relief="solid", borderwidth=1)
clear_btn = Button(root, width=var_width_small, relief="solid", borderwidth=1, text="clear", command=clearall)
copy_btn = Button(root, width=var_width_small, relief="solid", borderwidth=1, text="copy", command=clipboard)
list_btn = Button(root, width=var_width_small, relief="solid", borderwidth=1, text="store in list", command=addlist)
generate_btn = Button(root, width=var_width_extra, relief="solid", borderwidth=1, text="GENERATE!", command=generate)

length_lbl.grid(row=1, column=1, pady=1, padx=1)
output_lbl.grid(row=2, column=1, pady=1, padx=1)
name_lbl.grid(row=3, column=1, pady=1, padx=1)
length_entry.grid(row=1, column=2, pady=1, padx=1)
output_entry.grid(row=2, column=2, pady=1, padx=1)
name_entry.grid(row=3, column=2, pady=1, padx=1)
clear_btn.grid(row=1, column=3, pady=1, padx=1)
copy_btn.grid(row=2, column=3, pady=1, padx=1)
list_btn.grid(row=3, column=3, pady=1, padx=1)
generate_btn.grid(row=4, column=1, columnspan=3)
root.mainloop()
__deets__
User
Beiträge: 3077
Registriert: Mittwoch 14. Oktober 2015, 14:29

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: 45
Registriert: Mittwoch 5. April 2017, 20:53
Wohnort: Hannover

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: 45
Registriert: Mittwoch 5. April 2017, 20:53
Wohnort: Hannover

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'
__deets__
User
Beiträge: 3077
Registriert: Mittwoch 14. Oktober 2015, 14:29

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: 3
Registriert: Donnerstag 26. Oktober 2017, 07:37
Wohnort: Osthessen

Freitag 9. Februar 2018, 13:24

Bei mir funktioniert es mit dieser Setup.py.

Code: Alles auswählen

import cx_Freeze
import sys
import os

base = None
os.environ["TCL_LIBRARY"] = r"C:\Users\Tim Piglowski\AppData\Local\Programs\Python\Python36-32\tcl\tcl8.6"
os.environ["TK_LIBRARY"] = r"C:\Users\Tim Piglowski\AppData\Local\Programs\Python\Python36-32\tcl\tk8.6"

# GUI applications require a different base on Windows (the default is for a
# console application).
if sys.platform == "win32":
    base = "Win32GUI"
#if sys.platform == "win32":
#    base = "console"

executables = [cx_Freeze.Executable("PasswordGen.py", base = base)] #, icon="Icon.ico")]

cx_Freeze.setup(
    name="PasswordGenerator",
    options = {"build_exe": {"packages":["tkinter"], "include_files":[r"C:\Users\Tim Piglowski\AppData\Local\Programs\Python\Python36-32\DLLs\tcl86t.dll",
                                                                      r"C:\Users\Tim Piglowski\AppData\Local\Programs\Python\Python36-32\DLLs\tk86t.dll",
                                                                      "PWG.ico"]}},  
    version = "1.0",
    description = "A simple, python-based, password generator",
    executables = executables
    )
"Habs gleich"
Antworten