• Register
0 votes
34 views

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.

10 7 2
6,050 points

1 Answer

0 votes

Your location of you DLL tool file must be added in your setup.py file. Default directory for your DLL tool file should be:

C:\Users\USER\AppData\Local\Programs\Python\DLLs

You must add a variable to store this path.
Then i should be converted in raw string with

r

That code should be like:

​
systempath = r'​C:\Users\USER\AppData\Local\Programs\Python\DLLs'

 

11 6 4
34,930 points

Related questions

0 votes
3 answers 190 views
190 views
I am new in python programming. I am tryin gto iinstall some packages with pip commands. I tried to install a package called unroll by using the command: pip[ install unroll but it gives me some error like : "python setup.py egg_info" failed with error code 1 How can I solve this problem? How can I check my pip version? How can I upgrade my pip version?
asked Mar 9 LizzyM 6.1k points
0 votes
1 answer 129 views
129 views
I am new to python programming language and I don;t know how to fix it. This is my code below : from PIL import image import pytesseract ig = image.open(“Horse.jpg”) text = pytesseract.image_to_string(ig, lang=’eng’) print(text)
asked Mar 8 sstones 830 points
2 votes
1 answer 24 views
24 views
Problem: I am new in programming language. I was trying to setup and then upgrade gcloud using python. I used the command: pip install --upgrade gcloud After that it shows: Collecting gcloud Downloading gcloud-0.18.3.tar.gz (454kB) 100% | ... code 1 in C:\Users\bid\AppData\Local\Temp\pip-build-ppc44asr\googleapis-common-protos\ Whats is happening here can anyone help?
asked Mar 24 LizzyM 6.1k points
0 votes
1 answer 11 views
11 views
Problem: I am new to programming language. Yesterday I installed python in system. I went to my command prompmt and run the command : python and it shows: Python 3.7.6 (tags/v3.7.6:43364a7ae0, Dec 19 2019, 01:54:44) [MSC v.1916 64 bit (AMD64)] on ... a different output : python' is not recognized as an internal or external command, operable program or batch file Why am I seeig this , Please help.
asked Mar 22 LizzyM 6.1k points