1

I have a basic python script, Its a speech recognition script to let me shutdown my pc through voice commands and some additional stuff to have a tray icon. I have provided all of the code entirely as its not much. This works perfectly when I run it through the command line with python. However when I pack it into an exe file with pyinstaller I get the following errors:

Failed to execute script pyiboot01_bootstrap

Error: 'NoneType' object has no attribute 'write'

Something to do with pyiboot01 and pyimod03

I ran pyinstaller with basically every available argument but to my understanding these should be the arguments I need:

pyinstaller --noconsole --onefile --add-data icon.png;. filename.py

I also tried it with console as a dir instead of a single file, etc.. always getting the same errors.

# Imports
import sys
import pystray
import os
import speech_recognition as sr
from PIL import Image
from pystray import Menu, MenuItem

def resource_path(relative_path):
    """ Get absolute path to resource, works for dev and for PyInstaller """
    try:
        # PyInstaller creates a temp folder and stores path in _MEIPASS
        base_path = sys._MEIPASS
    except Exception:
        base_path = os.path.abspath(".")

    return os.path.join(base_path, relative_path)

# Kill
def exit_action(icon):
    sys.exit(0)

# Tray icon
icon = pystray.Icon('pc-off',)
icon.menu = Menu(MenuItem('Exit', lambda : exit_action(icon)),)
icon.icon = Image.open(resource_path('icon.png'))
icon.title = 'pc-off'

icon.run()

# Voice Recognition
def callback(recognizer, audio):
    try:
        if(recognizer.recognize(audio) == "Python shut down PC" or recognizer.recognize(audio) == "Python shutdown PC" ):
            os.system("shutdown /s /t 1")
    except LookupError:
        pass
        
r = sr.Recognizer()
r.listen_in_background(sr.Microphone(), callback)

import time
while True: time.sleep(0.1)
djvg
  • 11,722
  • 5
  • 72
  • 103
Alp Orgun
  • 15
  • 7

0 Answers0