簡體   English   中英

PyQt5 應用程序使用 --onefile 和 --noconsole 使用 PyInstaller 編譯,但 exe 無法啟動

[英]PyQt5 app compiled with PyInstaller using --onefile and --noconsole, but exe fails to launch

使用 Qt Designer 和 PyQt5,我制作了一個簡單的應用程序,對 a.txt 文件進行一些簡單的修改並保存它。 我使用 PyInstaller 使用以下命令成功編譯了我的程序:

pyinstaller --distpath DESTINATION_PATH --onefile --noconsole myscript.py

可執行文件已創建,但是當我嘗試運行它時,我收到一條錯誤消息,指出應用程序無法啟動,因為它的並排配置不正確 如果我不使用 --noconsole,可執行文件運行良好,但這不是我打算運行它的方式。 我對 PyQt5 和 PyInstaller 相當陌生,我在某處讀到我的程序在使用 --noconsole 時不應包含“子進程”,但我不完全確定這意味着什么。 如果有任何相關性,我的防病毒軟件在使用--onefile --noconsole 編譯時會刪除.exe,但在僅使用--onefile 時不會。 但是,這個問題很快就通過創建異常解決了。

這是我使用的導入:

import sys, re, os
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QMainWindow, QFileDialog, QApplication, QMessageBox
from pathlib import Path
import pyperclip as pc

ThePyGuy 上面提供的答案已經解決了這個問題。 在 spec 文件中添加hiddenimports=['pyperclip']足以防止錯誤發生,並且程序運行良好到我測試它的程度。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM