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)
AMC
  • 2,642
  • 7
  • 13
  • 35
Chili
  • 3
  • 1
  • 5
  • Does this answer your question? [How can I convert a .py to .exe for Python?](https://stackoverflow.com/questions/41570359/how-can-i-convert-a-py-to-exe-for-python) –  Jan 17 '20 at 20:53

1 Answers1

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 """
martineau
  • 119,623
  • 25
  • 170
  • 301