I code in PyCharm and went into C:\Users\MyUser\PyCharmProjects\MyFile and from there went into cmd in that directory, executed pyinstaller --onefile -w main.py. This worked perfect. I grabbed my main.exe from dist and put it into MyFile and executed it but upon doing so it brought up the following error:
Traceback (most recent call last):
File "main.py", line 2, in <module>
from pynput.mouse import Controller, Button
File "PyInstaller\loader\pyimod03_importers.py", line 540, in exec_module
File "pynput\__init__.py", line 40, in <module>
File "PyInstaller\loader\pyimod03_importers.py", line 540, in exec_module
File "pynput\keyboard\__init__.py, line 31, in <module>
File "pynput\_util\__init__.py", line 76, in backend
ImportError
[4752] Failed to execute script main
The purpose of my code is to move around your mouse rapidly until you hold down a, b, and c. Just a fun practical joke. Here is a copy of it:
import keyboard
from pynput.mouse import Controller, Button
import random
import tkinter as tk
root = tk.Tk()
mouse = Controller()
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
while True:
xVar = random.randint(0, screen_width)
yVar = random.randint(0, screen_height)
mouse.position = (xVar, yVar)
if keyboard.is_pressed("a") and keyboard.is_pressed("b") and keyboard.is_pressed("c"):
break
I've honestly tried everything. I can't figure out what is going wrong with it. Any help would be appreciated. Thanks!