0

I'm trying to deploy a single file app using python 3.8.5 and a tkinter gui. Using pyinstaller works to create the .exe, but running it immediately returns Fatal Error. My environment Windows 10, Atom IDE, python 3.8.5, tkinter gui

There are 8 mp4 videos the gui buttons should be able to launch from the gui. I implemented a media folder to hold all the media files in the dev environment can't figure out how to call them in the script.

from tkinter import *
from tkinter import ttk
import sys
from os import startfile
from PIL import Image, ImageTk
import win32com.client as win32
# cwd = os.getcwd()
# cfig = cwd + "/aws_guide/config.ini" # declares the path to the videos
# print(cfig)
class Vp:
 img = '/aws_guide/media/skllp.png'
 ast = 'Accessing the Workspace for the first time.mp4'
 favs = 'Import Bookmarks.mp4'
 otds = 'Logging off-Disconnecting-Rebooting.mp4'
 ntdriv = "C:/Users/mrhoda/Documents/scripts/aws_guide/Navigating Network Drives.mp4"
 oot = "C:/Users/mrhoda/Documents/scripts/aws_guide/Outlook Tour.mp4"
 pwrt = "C:/Users/mrhoda/Documents/scripts/aws_guide/Reset your password.mp4"
 aoot = "C:/Users/mrhoda/Documents/scripts/aws_guide/Setting up Outlook for the 1st time.mp4"
 findie = "C:/Users/mrhoda/Documents/scripts/aws_guide/Finding IE.mp4"
 ptm = "[email protected];[email protected]"
 kath = "[email protected];[email protected];[email protected]"
class Window(Frame):
 def __init__(self, master=None):
 Frame.__init__(self, master)
 self.master = master
 self.pack(fill=BOTH, expand=1)
 load = Image.open(Vp.img)
 render = ImageTk.PhotoImage(load)
 img = Label(self, image=render)
 img.image = render
 img.place(x=0, y=0)
 ttk.Frame(root, padding="3 3 12 12")
def ICShelp(ptm):
 outlook = win32.Dispatch('outlook.application')
 mail = outlook.CreateItem(0)
 mail.To = ptm
 mail.Subject = "Workspaces Help"
 mail.HtmlBody = ""
 mail.Display(True)
def imanhelp(kath):
 outlook = win32.Dispatch('outlook.application')
 mail = outlook.CreateItem(0)
 mail.To = kath
 mail.Subject = "iManage Help"
 mail.HtmlBody = ""
 mail.Display(True)
def err():
 # lazy error handler
 pass
def close():
 sys.exit()
root = Tk()
root.title("Getting to Know AWS Workspaces")
app = Window(root)
root.geometry("1048x600") # good enough for now
root.columnconfigure(0, weight=1)
root.rowconfigure(0, weight=1)
ttk.Button(app, text="Getting Started with Workspaces", command=lambda: startfile(Vp.ast)).grid(column=1, row=1, sticky=W)
ttk.Button(app, text="Setup Outlook", command=lambda: startfile(Vp.aoot)).grid(column=1, row=2, sticky=W)
ttk.Button(app, text="Tour Outlook", command=lambda: startfile(Vp.oot)).grid(column=1, row=3, sticky=W)
ttk.Button(app, text="How to Reset Your Password", command=lambda: startfile(Vp.pwrt)).grid(column=1, row=4, sticky=W)
ttk.Button(app, text="How to Find Internet Explorer", command=lambda: startfile(Vp.findie)).grid(column=1, row=5, sticky=W)
ttk.Button(app, text="Clone Your Browser Favorites", command=lambda: startfile(Vp.favs)).grid(column=1, row=6, sticky=W)
ttk.Button(app, text="Navigating Your Folders", command=lambda: startfile(Vp.ntdriv)).grid(column=1, row=7, sticky=W)
ttk.Button(app, text="Login/Logout Or Disconnect", command=lambda: startfile(Vp.otds)).grid(column=1, row=8, sticky=W)
ttk.Button(app, text="I need ICS Help", command=lambda: ICShelp(Vp.ptm)).grid(column=1, row=9, sticky=W)
ttk.Button(app, text="I need iManage Help", command=lambda: imanhelp(Vp.kath)).grid(column=1, row=10, sticky=W)
root.mainloop()
close()

It runs perfectly from Atom. This is my 1st python with a gui. Much appreciated!

Adendum: Thanks Cool Cloud! It's compiled with

pyinstaller --onefile 
--add-data 'C:/Users/mrhoda/Documents/scripts/aws_guide/media/skllp.png;.' 
--add-data 'C:/Users/mrhoda/Documents/scripts/aws_guide/media/Accessing the Workspace for the first time.mp4;.'
--add-data 'C:/Users/mrhoda/Documents/scripts/aws_guide/media/Finding IE.mp4;.' 
--add-data 'C:/Users/mrhoda/Documents/scripts/aws_guide/media/Import Bookmarks.mp4;.' 
--add-data 'C:/Users/mrhoda/Documents/scripts/aws_guide/media/Logging off-Disconnecting-Rebooting.mp4;.' 
--add-data 'C:/Users/mrhoda/Documents/scripts/aws_guide/media/Navigating Network Drives.mp4;.' 
--add-data 'C:/Users/mrhoda/Documents/scripts/aws_guide/media/Outlook Tour.mp4;.' 
--add-data 'C:/Users/mrhoda/Documents/scripts/aws_guide/media/Rest your password.mp4;.' 
--add-data 'C:/Users/mrhoda/Documents/scripts/aws_guide/media/Setting up Outlook for the 1st time.mp4;.' awstrainer.py

I got this in the Traceback:

C:\Users\mrhoda>C:\Users\mrhoda\Documents\scripts\aws_guide\dist\awstrainer.exe
Traceback (most recent call last):
 File "awstrainer.py", line 74, in <module>
 File "awstrainer.py", line 37, in __init__
 File "PIL\Image.py", line 2878, in open
FileNotFoundError: [Errno 2] No such file or directory: '/aws_guide/media/skllp.png'
[13800] Failed to execute script awstrainer
asked Sep 20, 2020 at 20:47
12
  • Did you copy the exe from dist folder to the project directory? Also how did you compile it to an exe? pyinstaller? cxfreeze ? auto-py-to-exe? Whats the line of code used. If its pyinstaller then make a new exe by saying pyinstaller -c -F script.py and post the error code that comes up in the console. Commented Sep 20, 2020 at 21:04
  • Thanks Cool Cloud! Commented Sep 20, 2020 at 21:30
  • Would be better to update the Q with this Commented Sep 20, 2020 at 21:32
  • Can you say print(cfig) and tell me what it is? And does this issue happen when you run the script.py or just when using exe? Commented Sep 20, 2020 at 21:38
  • 1
    I got mad and completely stripped out the config file import, reset class VP to be the variables = absolute paths.......it works as .exe now! It didn't package any of the content so I still can't send it out yet, but it at least runs and pulls from those absolute paths. Thanks @CoolCloud ! Commented Sep 20, 2020 at 22:36

1 Answer 1

1

I wasn't calling the relative paths correctly for the pyinstaller. Thanks again @CoolCloud for looking at this thing! Kudos to @NL23codes, your answer here got me to the finish line.

from tkinter import *
from tkinter import ttk
import sys
import os
from os import startfile
from PIL import Image, ImageTk
import win32com.client as win32
def resource_path(relative_path):
 """ Get absolute path to resource, works for dev and for PyInstaller """
 base_path = getattr(
 sys,
 '_MEIPASS',
 os.path.dirname(os.path.abspath(__file__)))
 return os.path.join(base_path, relative_path)
class Vp():
 Logo = resource_path("skllp.png")
 ast = resource_path("Accessing the Workspace for the first time.mp4")
 favs = resource_path("Import Bookmarks.mp4")
 otds = resource_path("Logging off-Disconnecting-Rebooting.mp4")
 ntdriv = resource_path("Navigating Network Drives.mp4")
 oot = resource_path("Outlook Tour.mp4")
 pwrt = resource_path("Reset your password.mp4")
.....etc

It still took a big pyinstaller command

pyinstaller --onefile --add-data 'C:/Users/mrhoda/Documents/scripts/aws_guide/skllp.png;.' --add-data 'C:/Users/mrhoda/Documents/scripts/aws_guide/Accessing the Workspace for the first time.mp4;.'--add-data 'C:/Users/mrhoda/Documents/scripts/aws_guide/Finding IE.mp4;.' --add-data 'C:/Users/mrhoda/Documents/scripts/aws_guide/Import Bookmarks.mp4;.' --add-data 'C:/Users/mrhoda/Documents/scripts/aws_guide/Logging off-Disconnecting-Rebooting.mp4;.' --add-data 'C:/Users/mrhoda/Documents/scripts/aws_guide/Navigating Network Drives.mp4;.' --add-data 'C:/Users/mrhoda/Documents/scripts/aws_guide/Outlook Tour.mp4;.' --add-data 'C:/Users/mrhoda/Documents/scripts/aws_guide/Rest your password.mp4;.' --add-data 'C:/Users/mrhoda/Documents/scripts/aws_guide/Setting up Outlook for the 1st time.mp4;.' awstrainer.py

But it does work now. The relative path part was the key.

answered Sep 25, 2020 at 17:53
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.