Solution: Failed to execute script appears when the exe file is opened after PyInstaller is packaged

def resource_path(self, relative):
        if hasattr(sys, "_MEIPASS"):
            return os.path.join(sys._MEIPASS, relative)
        return os.path.join(relative)

def copy_GUI(self):
        root = tkinter.Tk()
        root.title( " U disk copy gadget v6.0 " )
        root.geometry("400x260")
        icopath = self.resource_path(r"D:\python_workshop\python6\personal_practices\favicon-20180501101520441.ico")
        if os.path.exists(icopath):
            root.iconbitmap(icopath)

The red code above is the code that needs to be added

In addition, you need to modify the packaged spec file, add [  (' favicon-20180501101520441.ico ' ,'D:\\ python_workshop \\python6\\personal_practices\\favicon-20180501101520441.ico',' DATA') ]. InI  

Repackage through PyInstaller -w D:\python_workshop\python6\personal_practices\udisk_copy v6.0.py. Then run it and find that everything is ok

 

refer to:

https://blog.csdn.net/you227/article/details/46989625

http://tieba.baidu.com/p/3060401749

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325107690&siteId=291194637