0

Hello so I have made I python script but now I want to make it into an .exe or .bat. I have tried using pyinstaller using the command:

pyinstaller --onefile Pythonscript.py 

and it works but when I try to run it I get a popup message saying

Error Python Script unable to run.

I have no idea how to fix this.

And here's my script

import time
from pynput.keyboard import Key, Controller

keyboard = Controller()

time.sleep(2)

keyboard.press(Key.cmd)
keyboard.press(Key.cmd)
keyboard.press('r')

time.sleep(2)

keyboard.release('r')
keyboard.release(Key.cmd)
keyboard.release(Key.cmd)

time.sleep(2)

keyboard.type('https://www.youtube.com/watch?v=dQw4w9WgXcQ')

time.sleep(2)

keyboard.press(Key.enter)

time.sleep(2)

keyboard.release(Key.enter)
1

1 Answer 1

1

Long ago I found this template somewhere, which might help:

@echo off
rem = """
rem Do any custom setup like setting environment variables etc if required here ...

python -x "%~f0" %*
goto endofPython """

# Your python code goes here ..

if __name__ == "__main__":
    print("Hello World from Python")

rem = """
:endofPython """
Sign up to request clarification or add additional context in comments.

2 Comments

Should i type that in notepad or python? And what should the extension be?
It's (sort-of) a Windows batch file, so you should use a text editor like Notepad.

Your Answer

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.