Python 获得;无法执行脚本";用于pyinstaller
我正在尝试创建一个程序,当打开它时,它不会做任何事情,但是如果你按下键盘上的某些字母,就会弹出一张约翰·塞纳的照片。我已经设法让它在IDE中完美地工作,但当我尝试使用pyinstaller将.py文件转换为.exe文件时,它无法工作 每次启动.exe文件时,它都会显示: 执行脚本时出现致命错误 我怎么解决这个问题,因为我已经尝试了很多方法,现在我已经失去理智了 代码如下:Python 获得;无法执行脚本";用于pyinstaller,python,pyinstaller,Python,Pyinstaller,我正在尝试创建一个程序,当打开它时,它不会做任何事情,但是如果你按下键盘上的某些字母,就会弹出一张约翰·塞纳的照片。我已经设法让它在IDE中完美地工作,但当我尝试使用pyinstaller将.py文件转换为.exe文件时,它无法工作 每次启动.exe文件时,它都会显示: 执行脚本时出现致命错误 我怎么解决这个问题,因为我已经尝试了很多方法,现在我已经失去理智了 代码如下: from pynput.keyboard import Key, Listener from PIL import Imag
from pynput.keyboard import Key, Listener
from PIL import Image, ImageTk
import threading
import tkinter as tk
import os
import sys
threads = {}
def resource_path(relative_path):
base_path = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__)))
return os.path.join(base_path, relative_path)
def Open():
window = tk.Tk()
window.title("JOHN CENA!!!!!!!!!!!!!!!!!!")
window.geometry("620x400")
window.configure(background='grey')
img = ImageTk.PhotoImage(Image.open(resource_path('Jhonny.jpg')), master=window)
panel = tk.Label(window, image=img)
panel.pack(side="bottom", fill="both", expand="yes")
window.attributes("-topmost", True)
window.mainloop()
def on_press(key):
try:
KEY = key.char.lower()
if KEY in ['a', 'e', 'i', 'o', 'u']:
thread_id = len(threads) + 1
threads[thread_id] = threading.Thread(target=Open)
threads[thread_id].start()
except:
pass
return True
with Listener(on_press=on_press) as listener:
listener.join()
您是否已将exe复制到项目目录?然后键入
pyinstaller-F-c filename.py
,启动exe并在控制台窗口中检查错误代码,然后将其发布到此处。