No module named keyboard after converting py to exe - python

I am making an application which automatically enters your username and password. Everything works fine but when I try to convert it to .exe using auto-py-to-exe I get this error when I launch main.exe. I have added the modules in the hidden-import menu but it doesn't seem to work. I'm pretty new to this so please keep the answers more simple :D Here is the code of the actual program:
from pynput.mouse import Button
import keyboard
from pynput.keyboard import Key, Controller, Listener, KeyCode
mouse = Controller()
keyboards = Controller()
f = open("parolochetach.txt", "r")
list_of_lists = []
for line in f:
stripped_line = line.strip()
line_list = stripped_line.split()
list_of_lists.append(line_list)
f.close()
while True:
if keyboard.is_pressed('1') or keyboard.is_pressed('2') or keyboard.is_pressed('3') or keyboard.is_pressed('4') or\
keyboard.is_pressed('5') or keyboard.is_pressed('6') or keyboard.is_pressed('7') or keyboard.is_pressed('8')\
or keyboard.is_pressed('9'):
number = int(keyboard.read_key())
if number-1 <= len(list_of_lists):
mouse.position = (404, 415)
mouse.press(Button.left)
mouse.release(Button.left)
keyboards.type(list_of_lists[number-1][0])
mouse.position = (404, 465)
mouse.press(Button.left)
mouse.release(Button.left)
keyboards.type(list_of_lists[number-1][1])
keyboards.press(Key.enter)
keyboards.release(Key.enter)
I also tried to avoid using the keyboard module but I can't make it work. When I do something simple like:
def on_press(key):
if key==KeyCode.from_char('1'):
print("yes")
it works with no errors but when I add the click and type functions:
number = int(key)
if number - 1 <= len(list_of_lists):
mouse.position = (404, 415)
mouse.press(Button.left)
mouse.release(Button.left)
keyboards.type(list_of_lists[number - 1][0])
mouse.position = (404, 465)
mouse.press(Button.left)
mouse.release(Button.left)
keyboards.type(list_of_lists[number - 1][1])
keyboards.press(Key.enter)
keyboards.release(Key.enter)
it stops working and I get multiple errors:
Unhandled exception in listener callback
File"myfile", line 211, ni inner return f(self,*args, **kwargs)
File "", line 284, in _process
self.on_press(key)
File "", line 127, in inner
if f(*args) is False:
File "", line 17, in on_press
number = int(key)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'KeyCode'
Traceback (most recent call last):
File "", line 31, in <module>
listener.join()
File "", line 259, in join
six.reraise(exc_type, exc_value, exc_traceback)
File "", line 718, in reraise
raise value.with_traceback(tb)
File "", line 211, in inner
return f(self, *args, **kwargs)
File "", line 284, in _process
self.on_press(key)
File "", line 127, in inner
if f(*args) is False:
File "", line 17, in on_press
number = int(key)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'KeyCode'

This is my answer for another question here and it did work in that case.
Try using pyinstaller and if it can't find modules try this:
From Documentation
Helping PyInstaller Find Modules
Extending the Path If Analysis recognizes that a module is needed, but
cannot find that module, it is often because the script is
manipulating sys.path. The easiest thing to do in this case is to use
the --paths option to list all the other places that the script might
be searching for imports:
pyi-makespec --paths=/path/to/thisdir
--paths=/path/to/otherdir myscript.py
These paths will be noted in the spec file in the pathex argument.
They will be added to the current sys.path during analysis.

Related

Using pyrcl for trace32

Iam trying to remotely control the trace32 and trying to add commands from pyhton, in this process i have to set break point using python but i cannot set as its saying the function name is not defined (i have already flashed my hex and elf) other functions such as symbol name is working well
import lauterbach.trace32.rcl as t32
dbg = t32.autoconnect()
self = dbg.symbol.query_by_name(name='ComMainFunctionTx')
print(self)
bp = dbg.breakpoint.set(*"ComComMainFunctionTx ",**())
This is my output iam not understanding what to keep here for mapping
ComComMainFunctionTx P:0x801bacf0 930
Traceback (most recent call last):
File "c:\Users\Desktop\test hello.py", line 24, in <module>
bpt=dbg.breakpoint.set(*"ComComMainFunctionTx ",**())
TypeError: lauterbach.trace32.rcl._rc._breakpoint.BreakpointService.set() argument after ** must be a mapping, not tuple
update
this is what iam trying to do , iam adding dbg.go_return() to go to the next breakpoint but its throwing timedout error please help if i manually press go button its going to the next breakpoint in trace32 but giving bp.go() its giving timedout error
data=pd.read_csv("useR1.csv")
# converting column data to list
ARG = data['Arguments'].tolist()
for i in ARG:
mysys = dbg.symbol.query_by_name(name=i)
bp = dbg.breakpoint.set(address=mysys.address)
dbg.go_return()
Break
File "c:\Users\Desktop\IT_Script\test hello.py", line 70, in <module>
dbg.go_return()
File "C:\Users\AppData\Local\Programs\Python\Python310\lib\site-packages\lauterbach\trace32\rcl\rcl.py", line 429, in go_return
self.cmd("Go.Return")
File "C:\Users\AppData\Local\Programs\Python\Python310\lib\site-packages\lauterbach\trace32\rcl\_rc\_command.py", line 16, in __call__
self.__conn._cmd(cmd)
File "C:\Users\AppData\Local\Programs\Python\Python310\lib\site-packages\lauterbach\trace32\rcl\rcl.py", line 284, in _cmd
self.__library.t32_executecommand(cmd.encode(), 4096)
File "C:\Users\AppData\Local\Programs\Python\Python310\lib\site-packages\lauterbach\trace32\rcl\_rc\_library.py", line 429, in t32_executecommand
return self.generic_api_call(
File "C:\Users\AppData\Local\Programs\Python\Python310\lib\site-packages\lauterbach\trace32\rcl\_rc\_library.py", line 313, in generic_api_call
recv_data = self._link.receive()
File "C:\Users\AppData\Local\Programs\Python\Python310\lib\site-packages\lauterbach\trace32\rcl\_rc\hlinknet.py", line 649, in receive
raise ApiConnectionTimeoutError(str(e)) from None
lauterbach.trace32.rcl._rc._error.ApiConnectionTimeoutError: timed out
This should work:
import lauterbach.trace32.rcl as t32
dbg = t32.autoconnect()
sym = dbg.symbol.query_by_name(name='ComMainFunctionTx')
print(sym)
bp = dbg.breakpoint.set(address=sym.address)
print(bp)

Pynput with pyinstaller 1.7.0

I have a pynput error "COMBINING APOSTROPHY" when inputting a single quote into the listener with the international keyboard. I realize most people won't have this problem, but I want to handle that case.
I've looked it up and it seems to be an issue with pynput==1.6.8 and it's fixed in pynput==1.7.0^.
The problem is that I'm using pyinstaller to convert my script into an executable, and I like pyinstaller because it can also make executables for macOS and Linux, but pyinstaller doesn't work with pynput==1.7.0, the latest version it works with is pynput==1.6.8.
When using pynput==1.7.0, the generated .exe gives the descriptive error: Failed to execute script logger
Is there a way I can skip the combining apostrophe and not have the whole script crash with pynput==1.6.8?
Is there a way I can use pynput==1.7.0^ with pyinstaller?
Are there alternatives to pyinstaller that are better that can still generate executables for other OSs?
Maybe alternatives to pynput? Although I've had a hard time finding something as simple as pynput
I've been doing pyinstaller --onefile -w logger.py to convert my scripts.
The code for my script:
def on_press(key):
global keys, count
print(f"key = {key}")
keys.append(key)
count += 1
# reset
if count >= 1:
count = 0
write_file(keys)
keys = []
def on_release(key):
if key == Key.esc:
return False
if __name__ == "__main__":
with Listener(on_press=on_press, on_release=on_release) as listener:
listener.join()
The error I receive is:
Unhandled exception in listener callback
Traceback (most recent call last):
File "...\Programs\Python\Python39\lib\site-packages\pynput\_util\__init__.py", line 162, in inner
return f(self, *args, **kwargs)
File "...\Programs\Python\Python39\lib\site-packages\pynput\keyboard\_win32.py", line 275, in _process
key = self._event_to_key(msg, vk)
File "...\Programs\Python\Python39\lib\site-packages\pynput\keyboard\_win32.py", line 314, in _event_to_key
return KeyCode(**self._translate(
File "...\Programs\Python\Python39\lib\site-packages\pynput\keyboard\_base.py", line 52, in __init__
self.combining = unicodedata.lookup(
KeyError: "undefined character name 'COMBINING APOSTROPHE'"
Traceback (most recent call last):
File "...\logger.py", line 54, in <module>
listener.join()
File "...\Programs\Python\Python39\lib\site-packages\pynput\_util\__init__.py", line 210, in join
six.reraise(exc_type, exc_value, exc_traceback)
File "...\Programs\Python\Python39\lib\site-packages\six.py", line 702, in reraise
raise value.with_traceback(tb)
File "...\Programs\Python\Python39\lib\site-packages\pynput\_util\__init__.py", line 162, in inner
return f(self, *args, **kwargs)
File "...\Programs\Python\Python39\lib\site-packages\pynput\keyboard\_win32.py", line 275, in _process
key = self._event_to_key(msg, vk)
File "...\Programs\Python\Python39\lib\site-packages\pynput\keyboard\_win32.py", line 314, in _event_to_key
return KeyCode(**self._translate(
File "...\Programs\Python\Python39\lib\site-packages\pynput\keyboard\_base.py", line 52, in __init__
self.combining = unicodedata.lookup(
KeyError: "undefined character name 'COMBINING APOSTROPHE'"
There won't be any way to fix this without updating to a more recent version of pynput. If pyinstaller does not work for this then you will need to use something else. I don't know any linux executable compilers, but you could try dmgbuild for mac.
You could also try an alternative like pyautogui but it does not have all of the same functionalities as pynput. This just seems to be an issue between pyinstaller and pynput and unfortunately I don't see a lot you could do to fix this.

I am getting an error with tkinter ' bad window path name .!button2 ' and I am not sure why?

I am making a password management system in Tkinter but while deleting an entry I am getting this error:
Exception in Tkinter callback
Traceback (most recent call last):
File "/Users/user/opt/anaconda3/lib/python3.8/tkinter/__init__.py", line 1883, in __call__
return self.func(*args)
File "/Users/user/opt/anaconda3/lib/python3.8/site-packages/tkmacosx/basewidget.py", line 1094, in cmd
self.cnf['command']()
File "main.py", line 149, in delete
i.destroy()
File "main.py", line 169, in destroy
self.showButton.destroy()
File "/Users/user/opt/anaconda3/lib/python3.8/site-packages/tkmacosx/variables.py", line 55, in _patch
return fn(self)
File "/Users/user/opt/anaconda3/lib/python3.8/site-packages/tkmacosx/basewidget.py", line 1313, in destroy
main_win = self.winfo_toplevel()
File "/Users/user/opt/anaconda3/lib/python3.8/tkinter/__init__.py", line 1223, in winfo_toplevel
return self._nametowidget(self.tk.call(
_tkinter.TclError: bad window path name ".!button2"
this is a snippet from the code where I am getting an error:
def delete(self):
row = self.deleteButton.grid_info()['row'] # this will get the row you want to delete
ask = messagebox.askquestion("Are You Sure", "are you sure you want to delete this?")
if ask == "yes":
for i in objects: # TODO: cannot delete more than one entry after logging in.
i.destroy()
file = open('app_manager.txt', 'r')
lines = file.readlines()
file.close()
del lines[row - 6] # this will delete the data-entry from 'app_manager.txt'
file = open("app_manager.txt", "w")
for line in lines:
file.write(line)
file.close()
readfile()
NOTE: I can delete one entry but if I try and delete another entry then it shows the error I mentioned above.
If you need full code to inspect then this is the link:
https://github.com/vendz/Account-Storage-System/blob/master/main.py
The problem was with from tkmacosx import Button so instead use from tkinter import Button.
EDIT: problem with tkmacosx is now resolved. do update the package

pynput combining exclamation mark

I tried to make a little keylogger with pynput.
That's my code:
from pynput.keyboard import Key, Listener
import os
import logging
log_dir = "C:\WindowsLogs\dist"
filename = "logging"
logging.basicConfig(filename=(log_dir + filename), level=logging.DEBUG, format='%(asctime)s: %(message)s')
def on_press(key):
logging.info(str(key))
with Listener(on_press=on_press) as listener:
listener.join()
Everything works fine and it also does save every key. But when the exclamation mark is pressed it gets that error:
Traceback (most recent call last):
File "test2.py", line 16, in <module>
listener.join()
File "C:\Python27\lib\site-packages\pynput\_util\__init__.py", line 185, in join
six.reraise(exc_type, exc_value, exc_traceback)
File "C:\Python27\lib\site-packages\pynput\_util\__init__.py", line 140, in inner
return f(self, *args, **kwargs)
File "C:\Python27\lib\site-packages\pynput\keyboard\_win32.py", line 232, in _process
key = self._event_to_key(msg, vk)
File "C:\Python27\lib\site-packages\pynput\keyboard\_win32.py", line 265, in _event_to_key
msg in self._PRESS_MESSAGES))
File "C:\Python27\lib\site-packages\pynput\keyboard\_base.py", line 49, in __init__
'COMBINING ' + unicodedata.name(self.char))
KeyError: "undefined character name 'COMBINING EXCLAMATION MARK'"
What is wrong with the code? And what does that mean?
I got it! It's a bug in pynput. Installed an older version and now it works perfectly!

Mouse control with python

I'm running Ubuntu 12.04 and working with python 2. I would like to be able to control my mouse, and I have found several different python modules intended to do this, but cannot get them to work.
I installed dogtail, but when I try:
dogtail.rawinput.click(x,y)
I get:
AttributeError: 'module' object has no attribute 'rawinput'
I then tried pymouse and although I used pip to install it when I import pymouse:
from pymouse import PyMouse
I get:
TypeError: Object value must be tuple, dictionary or DictWrapper: 0
I tried the uinput module as well but the mouse commands only seemed to work when placed in a loop, which is frustrating/ridiculous.
If anyone knows how to fix either of those problems/what I'm doing wrong/better or easier to use modules I would much appreciate the help.
I'll assume that my problem is the same as yours, given the limited error information. The full exception and traceback I got was:
>>> import pymouse
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/pymouse/__init__.py", line 95, in <module>
from unix import PyMouse, PyMouseEvent
File "/usr/local/lib/python2.7/dist-packages/pymouse/unix.py", line 53, in <module>
class PyMouseEvent(PyMouseEventMeta):
File "/usr/local/lib/python2.7/dist-packages/pymouse/unix.py", line 66, in PyMouseEvent
'client_died': False,
File "/usr/local/lib/python2.7/dist-packages/Xlib/ext/record.py", line 121, in create_context
ranges = ranges)
File "/usr/local/lib/python2.7/dist-packages/Xlib/protocol/rq.py", line 1403, in __init__
self._binary = apply(self._request.to_binary, args, keys)
File "/usr/local/lib/python2.7/dist-packages/Xlib/protocol/rq.py", line 1088, in to_binary
return apply(self.to_binary, varargs, keys)
File "<string>", line 3, in to_binary
File "/usr/local/lib/python2.7/dist-packages/Xlib/protocol/rq.py", line 523, in pack_value
data.append(self.type.pack_value(v))
File "/usr/local/lib/python2.7/dist-packages/Xlib/protocol/rq.py", line 1102, in pack_value
return apply(self.to_binary, (), value)
File "/usr/local/lib/python2.7/dist-packages/Xlib/protocol/rq.py", line 1088, in to_binary
return apply(self.to_binary, varargs, keys)
File "<string>", line 4, in to_binary
File "/usr/local/lib/python2.7/dist-packages/Xlib/protocol/rq.py", line 573, in check_value
vals.append(f.check_value(val[i]))
File "/usr/local/lib/python2.7/dist-packages/Xlib/protocol/rq.py", line 582, in check_value
raise TypeError('Object value must be tuple, dictionary or DictWrapper: %s' % val)
TypeError: Object value must be tuple, dictionary or DictWrapper: 0
Note the exception occurs in Xlib. I had version 0.15rc1 installed. Downgrading to 0.14 fixed the problem.
use pynput .
It can control mouse, keyboard, etc.
examples:
mouse = Controller()
# Set pointer position
mouse.position = (10, 20)
# Press and release
mouse.press(Button.left)
mouse.release(Button.left)
this is my piece of code
from pymouse import PyMouse
m = PyMouse()
m.click(654, 169,1)
the first two arguments ar for X,Y
the last argument to define wich click 1=left click 2=right
i wish it helps
m.click(x,y,click)
I recomend you install pyautogui. You can control mouse and write.
Example:
import pyautogui as py
py.move(x,y) #it moves the mouse
py.click(x,y) #click the mouse on a position
py.write('write this') #Write
py.press('enter') #press a key (enter in this case)

Categories