In an XML doument I was trying to build an python tool. It should distribute EXE form But it gives me an error like:
cx_freeze python error in main script-ImportError :DLL Load
my setup.py file is:
import sys
from cx_Freeze import setup, Executable
base = None
if sys.platform == 'win32':
base = 'Win32GUI'
executables = [
Executable('xin.py', base=base)
]
setup(name='XGen',
version='0.1',
description='XGen',
executables=executables
)
And the code I have written for my tool is:
from tkinter import filedialog
from tkinter import *
from pathlib import Path
import winsound
from lxml import etree
import csv
root = Tk()
root.geometry("250x200")
root.resizable(0, 0)
class gui:
def __init__(self, master):
self.master = master
master.title("XGen")
self.welcome = Label(master, text="Welcome to")
self.welcome.config(font=("Arial", 10))
self.welcome.pack()
self.header = Label(master, text="The XPath Generator")
self.header.config(font=("Arial", 16))
self.header.pack()
self.description = Label(master, text="This Tool Takes in an XML Document\nand Provides all its XPaths")
self.description.config(font=("Arial", 10))
self.description.pack()
self.greet_button = Button(master, text="Select Input XML", command=self.greet)
self.greet_button.pack()
self.reportFilename = Label(master, text="")
self.reportFilename.pack()
self.reportProgress = Label(master, text="")
self.reportProgress.pack()
# self.close_button = Button(master, text="Close", command=master.quit)
# self.close_button.pack()
def greet(self):
print("File Selection Started")
from_file_path = filedialog.askopenfilename(initialdir="/",
title="Select file",
filetypes=(("XML Files", "*.xml"), ("all files", "*.*")))
from_file_path_split = Path(from_file_path).parts
to_file_path = ''
if from_file_path is '':
self.reportFilename.config(text="You Did not Select a File")
print("No File Selected. File Selection Ended")
else:
self.reportFilename.config(text="You Selected " + from_file_path_split[-1])
print("From File Path = " + from_file_path)
print("File Name = " + from_file_path_split[-1])
to_file_path = filedialog.asksaveasfilename(initialdir=from_file_path,
title="Save As",
filetypes=(("CSV Files", "*.csv"), ("all files", "*.*")))
if to_file_path is '' or to_file_path == 'Null':
self.reportProgress.config(text="Please select a Save Location")
# elif to_file_split[-1][:4] == "xsd":
else:
to_file_split = Path(to_file_path).parts
to_file_name = to_file_split[-1]
print("Filename = " + to_file_name)
to_file_extension = to_file_split[-1][-4:]
print("Last 4 chars = " + to_file_extension)
if to_file_extension == ".csv":
pass
else:
to_file_path = to_file_path + ".csv"
# to_file_name = to_file_path
print("To File Path = " + to_file_path)
if from_file_path == '' or to_file_path == '' or to_file_path == 'Null':
self.reportProgress.config(text="Please Select a Valid XML File")
winsound.PlaySound("SystemExclamation", winsound.SND_ALIAS)
print("Bad File, Try Again")
else:
out(from_file_path, to_file_path)
self.reportProgress.config(text="Generated " + Path(to_file_path).parts[-1])
print("XGen Complete")
def out(in_path, out_path):
with open(in_path, 'r') as source_file:
xml = source_file.read()
root = etree.fromstring(xml)
tree = etree.ElementTree(root)
line = ['XPath', 'Attribute Name', 'Current Data']
from tkinter import filedialog
from tkinter import *
from pathlib import Path
import winsound
from lxml import etree
import csv
root = Tk()
root.geometry("250x200")
root.resizable(0, 0)
class gui:
def __init__(self, master):
self.master = master
master.title("XGen")
self.welcome = Label(master, text="Welcome to")
self.welcome.config(font=("Arial", 10))
self.welcome.pack()
self.header = Label(master, text="The XPath Generator")
self.header.config(font=("Arial", 16))
self.header.pack()
self.description = Label(master, text="This Tool Takes in an XML Document\nand Provides all its XPaths")
self.description.config(font=("Arial", 10))
self.description.pack()
self.greet_button = Button(master, text="Select Input XML", command=self.greet)
self.greet_button.pack()
self.reportFilename = Label(master, text="")
self.reportFilename.pack()
self.reportProgress = Label(master, text="")
self.reportProgress.pack()
# self.close_button = Button(master, text="Close", command=master.quit)
# self.close_button.pack()
def greet(self):
print("File Selection Started")
from_file_path = filedialog.askopenfilename(initialdir="/",
title="Select file",
filetypes=(("XML Files", "*.xml"), ("all files", "*.*")))
from_file_path_split = Path(from_file_path).parts
to_file_path = ''
if from_file_path is '':
self.reportFilename.config(text="You Did not Select a File")
print("No File Selected. File Selection Ended")
else:
self.reportFilename.config(text="You Selected " + from_file_path_split[-1])
print("From File Path = " + from_file_path)
print("File Name = " + from_file_path_split[-1])
to_file_path = filedialog.asksaveasfilename(initialdir=from_file_path,
title="Save As",
filetypes=(("CSV Files", "*.csv"), ("all files", "*.*")))
if to_file_path is '' or to_file_path == 'Null':
self.reportProgress.config(text="Please select a Save Location")
# elif to_file_split[-1][:4] == "xsd":
else:
to_file_split = Path(to_file_path).parts
to_file_name = to_file_split[-1]
print("Filename = " + to_file_name)
to_file_extension = to_file_split[-1][-4:]
print("Last 4 chars = " + to_file_extension)
if to_file_extension == ".csv":
pass
else:
to_file_path = to_file_path + ".csv"
# to_file_name = to_file_path
print("To File Path = " + to_file_path)
if from_file_path == '' or to_file_path == '' or to_file_path == 'Null':
self.reportProgress.config(text="Please Select a Valid XML File")
winsound.PlaySound("SystemExclamation", winsound.SND_ALIAS)
print("Bad File, Try Again")
else:
out(from_file_path, to_file_path)
self.reportProgress.config(text="Generated " + Path(to_file_path).parts[-1])
print("XGen Complete")
def out(in_path, out_path):
with open(in_path, 'r') as source_file:
xml = source_file.read()
root = etree.fromstring(xml)
tree = etree.ElementTree(root)
line = ['XPath', 'Attribute Name', 'Current Data']
It builds the Programm with an EXE but when the EXE runs it return the same error.