|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
这次写的程序用到了第三方库,再次遇到了打包不了exe的问题
打包成exe,运行提示Failed to execute script
用pycharm也不行,会出现以下提示
D:\Program Files\etBrains\PyCharm 2020.1\br\bin\PycharmProjects\untitled1\dist\scratch.exe
Traceback (most recent call last):
File "scratch.py", line 2, in <module>
File "PyInstaller \loader pyimod03_importers.py", line 531, in exec_module
File "pynput\__init__.py", line 40,in <module>
File "PyInstaller\loader \pyimod03 ,importers. py"'line 531, in exec_module
File "pynput\keyboard\___init__.py", line 31,in <module>
File "pynput\_util\_init_.py", line 76, in backend
ImportError
[10272] Failed to execute script scratch
小白表示不懂什么意思啊
是想自己试试弄个连点器,在python里运行是没有任何问题的,就是不知道为啥打不了包
- import win32api
- import win32con
- import pynput
- import ctypes
- import time
- from tkinter import *
- from tkinter.ttk import *
- import threading
- import os
- VK_CODE={
- 'backspace':0x08,
- 'tab':0x09,
- 'clear':0x0C,
- 'enter':0x0D,
- 'shift':0x10,
- 'ctrl':0x11,
- 'alt':0x12,
- 'pause':0x13,
- 'caps_lock':0x14,
- 'esc':0x1B,
- 'spacebar':0x20,
- 'page_up':0x21,
- 'page_down':0x22,
- 'end':0x23,
- 'home':0x24,
- 'left_arrow':0x25,
- 'up_arrow':0x26,
- 'right_arrow':0x27,
- 'down_arrow':0x28,
- 'select':0x29,
- 'print':0x2A,
- 'execute':0x2B,
- 'print_screen':0x2C,
- 'ins':0x2D,
- 'del':0x2E,
- 'help':0x2F,
- '0':0x30,
- '1':0x31,
- '2':0x32,
- '3':0x33,
- '4':0x34,
- '5':0x35,
- '6':0x36,
- '7':0x37,
- '8':0x38,
- '9':0x39,
- 'a':0x41,
- 'b':0x42,
- 'c':0x43,
- 'd':0x44,
- 'e':0x45,
- 'f':0x46,
- 'g':0x47,
- 'h':0x48,
- 'i':0x49,
- 'j':0x4A,
- 'k':0x4B,
- 'l':0x4C,
- 'm':0x4D,
- 'n':0x4E,
- 'o':0x4F,
- 'p':0x50,
- 'q':0x51,
- 'r':0x52,
- 's':0x53,
- 't':0x54,
- 'u':0x55,
- 'v':0x56,
- 'w':0x57,
- 'x':0x58,
- 'y':0x59,
- 'z':0x5A,
- 'numpad_0':0x60,
- 'numpad_1':0x61,
- 'numpad_2':0x62,
- 'numpad_3':0x63,
- 'numpad_4':0x64,
- 'numpad_5':0x65,
- 'numpad_6':0x66,
- 'numpad_7':0x67,
- 'numpad_8':0x68,
- 'numpad_9':0x69,
- 'multiply_key':0x6A,
- 'add_key':0x6B,
- 'separator_key':0x6C,
- 'subtract_key':0x6D,
- 'decimal_key':0x6E,
- 'pide_key':0x6F,
- 'F1':0x70,
- 'F2':0x71,
- 'F3':0x72,
- 'F4':0x73,
- 'F5':0x74,
- 'F6':0x75,
- 'F7':0x76,
- 'F8':0x77,
- 'F9':0x78,
- 'F10':0x79,
- 'F11':0x7A,
- 'F12':0x7B,
- 'F13':0x7C,
- 'F14':0x7D,
- 'F15':0x7E,
- 'F16':0x7F,
- 'F17':0x80,
- 'F18':0x81,
- 'F19':0x82,
- 'F20':0x83,
- 'F21':0x84,
- 'F22':0x85,
- 'F23':0x86,
- 'F24':0x87,
- 'num_lock':0x90,
- 'scroll_lock':0x91,
- 'left_shift':0xA0,
- 'right_shift ':0xA1,
- 'left_control':0xA2,
- 'right_control':0xA3,
- 'left_menu':0xA4,
- 'right_menu':0xA5,
- 'browser_back':0xA6,
- 'browser_forward':0xA7,
- 'browser_refresh':0xA8,
- 'browser_stop':0xA9,
- 'browser_search':0xAA,
- 'browser_favorites':0xAB,
- 'browser_start_and_home':0xAC,
- 'volume_mute':0xAD,
- 'volume_Down':0xAE,
- 'volume_up':0xAF,
- 'next_track':0xB0,
- 'previous_track':0xB1,
- 'stop_media':0xB2,
- 'play/pause_media':0xB3,
- 'start_mail':0xB4,
- 'select_media':0xB5,
- 'start_application_1':0xB6,
- 'start_application_2':0xB7,
- 'attn_key':0xF6,
- 'crsel_key':0xF7,
- 'exsel_key':0xF8,
- 'play_key':0xFA,
- 'zoom_key':0xFB,
- 'clear_key':0xFE,
- '+':0xBB,
- ',':0xBC,
- '-':0xBD,
- '.':0xBE,
- '/':0xBF,
- '`':0xC0,
- ';':0xBA,
- '[':0xDB,
- '//':0xDC,
- ']':0xDD,
- "'":0xDE,
- '`':0xC0}
- sig=0
- mouse=pynput.mouse.Controller()
- keyboard=pynput.keyboard.Controller()
- t=0
- lock=0
- def keyboardclick(virnum):
- Time=timeset.get()
- Time=float(Time)
- MapVirtualKey=ctypes.windll.user32.MapVirtualKeyA
- win32api.keybd_event(virnum,MapVirtualKey(virnum,0),0,0)
- time.sleep(0.001)
- win32api.keybd_event(virnum,MapVirtualKey(virnum,0),win32con.KEYEVENTF_KEYUP,0)
- time.sleep(Time)
- def click():
- Time=timeset.get()
- Time=float(Time)
- MCB.config(state=DISABLED)
- KCB.config(state=DISABLED)
- MRB.config(state=DISABLED)
- KRB.config(state=DISABLED)
- keyword=KCB.get()
- global lock
- lock=1
- while sig==1 and Time!=0 and v.get()==0 and MCB.get()=='左键':
- win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
- time.sleep(0.001)
- win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
- time.sleep(Time)
- count()
- while sig==1 and Time!=0 and v.get()==0 and MCB.get()=='右键':
- win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTDOWN,0,0,0,0)
- time.sleep(0.001)
- win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTUP,0,0,0,0)
- time.sleep(Time)
- count()
- while sig==1 and Time!=0 and v.get()==1:
- try:
- keyboardclick(VK_CODE[KCB.get()])
- count()
- except:
- break
- if v.get()==0:
- MCB.config(state='readonly')
- else:
- KCB.config(state=NORMAL)
- lock=0
- MRB.config(state=NORMAL)
- KRB.config(state=NORMAL)
- ## global t
- ## t=0
- ## numLabel.config(text=str(t))
- def startclick():
- global sig
- global lock
- if sig==0 and lock==0:
- sig=1
- thread=threading.Thread(target=click)
- thread.setDaemon(True)
- thread.start()
- timeset.config(state=DISABLED)
- else:
- sig=0
- timeset.config(state=NORMAL)
- def count():
- global t
- t+=1
- numLabel.config(text=str(t))
- def startlisten():
- with pynput.keyboard.GlobalHotKeys({
- '<f8>':startclick}) as hot:
- hot.join()
- def choice():
- c=v.get()
- if c==0:
- KCB.config(state=DISABLED)
- MCB.config(state='readonly')
- elif c==1:
- MCB.config(state=DISABLED)
- KCB.config(state=NORMAL)
- def resourcepath(relativepath):
- if hasattr(sys, '_MEIPASS'):
- basepath=sys._MEIPASS
- else:
- basepath=os.path.abspath('.')
- return os.path.join(basepath,relativepath)
- ico186ico=resourcepath('img\\ico186.ico')
- l=threading.Thread(target=startlisten)
- l.setDaemon(True)
- l.start()
- win=Tk()
- win.title('连点器V2.1')
- win.geometry('300x140')
- win.resizable(0,0)
- win.iconbitmap(ico186ico)
- numbutton=Label(win,text='下方为计数测试区\n请按<F8>开始连点',relief='solid')
- numbutton.place(x=20,y=10,anchor=NW)
- numLabel=Label(win,text=str(t))
- numLabel.place(x=72,y=50,anchor=N)
- timeLabel=Label(win,text='时间间隔:',font=('微软雅黑','12'))
- timeLabel.place(x=246,y=5,anchor=NE)
- timeset=Combobox(win,width=12)
- timeset.place(x=270,y=30,anchor=NE)
- timeset['value']=(1,0.5,0.2,0.1,0.05,0.02,0.01,0.001)
- timeset.current(3)
- v=IntVar()
- v.set(0)
- MRB=Radiobutton(win,text='鼠标',variable=v,value=0,command=choice)
- MRB.place(x=20,y=90,anchor=SW)
- MCB=Combobox(win,width=12)
- MCB.place(x=20,y=110,anchor=SW)
- MCB['value']=('左键','右键')
- MCB.current(0)
- MCB.config(state='readonly')
- KRB=Radiobutton(win,text='键盘(可自定义)',variable=v,value=1,command=choice)
- KRB.place(x=162,y=90,anchor=SW)
- KCB=Combobox(win,width=12)
- KCB.place(x=270,y=110,anchor=SE)
- KCB['value']=('a','b','c','F3','F5','enter','up_arrow')
- KCB.current(0)
- KCB.config(state=DISABLED)
- COPYRIGHT=Label(win,text='Copyright © 2020 Jerry·林 E-mail:1282387390@qq.com',font=('微软雅黑',8))
- COPYRIGHT.pack(side=BOTTOM)
- win.mainloop()
复制代码
把pynput卸载,安装1.6.8版本:pip install pynput==1.6.8
|
|