为什么我的 PyInstaller 生成的 .exe 无法启动?

Why does my .exe generated by PyInstaller not start?

我用 PyInstaller 生成了一个可执行文件,但是当我想启动应用程序时,控制台 window 显示它找不到目录或文件。我检查了位置,文件夹“_MEI55762”确实不存在。

以前有人遇到过这个问题吗?

下面这部分代码,我觉得应该是错误的地方。我认为这与“jsonrpclcient”包的导入有关。我没有 post 包含所有 GUI 行的完整代码,因为我认为这无济于事。如果我错了请告诉我。

import os
import sys
import requests
import json
import pyvisa
import time
from datetime import datetime
import threading
import signal
from jsonrpcclient import *
from jsonrpcclient.clients.http_client import HTTPClient
from jsonrpcclient.requests import Request
from tkinter import *
from tkinter import ttk
import traceback

print("-----------------------------------------")
print("              Q-Center V0.1              ")
print("-----------------------------------------")

port = ":8080"
rm = pyvisa.ResourceManager()

def listArticles():
    for attempt in range (3): #Will be executed 3 times in case an error occurs
        print('List Articles:')
        try: #First try this
            client = HTTPClient("http://" + ipEntry.get() + port)
            response = client.send(Request("list_articles"), timeout=5)
            print(response.data.result)
            print('Success!')
        except: #If an error occurs, call the print function and let the user know
            print('An error occured!')
            rebootPeacock()
            
        else: #If no error occurs, stop trying
            break

        
    else: #If no attempt was successful, print that all 3 attempts failed. ONLY EXCUTED WHEN THE LOOP DOES'T BREAK.
        print('All 3 attempts failed!')

    answer = response.data.result
    pkReply.insert(END, answer)
    pkReply.insert(END, '\n\n')

解决方案是告诉 PyInstaller 添加位于“C:\Users\pfra\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\jsonrpcclient”的“response-schema.json”文件。

所以命令应该是这样的:

pyinstaller --add-file "C:\Users\pfra\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\jsonrpcclient.response.schema.json;."