python - PyQt5 app compiled with PyInstaller using --onefile and --noconsole, but exe fails to launch
问题描述
Using Qt Designer and PyQt5, I have made a simple app that does some simple modifications on a .txt file and saves it. I successfully compiled my program using PyInstaller with the following command:
pyinstaller --distpath DESTINATION_PATH --onefile --noconsole myscript.py
The executable is created, but when I try to run it, I get an error saying that the application failed to start because its side-by-side configuration is incorrect. If I do not use the --noconsole, the executable runs fine but this is not how I intend to run it. I am fairly new to PyQt5 and PyInstaller, and I read somewhere that my program should not include "subprocesses" when using --noconsole but I am not entirely sure what that means. If of any relevance, my antivirus was deleting the .exe when compiled with --onefile --noconsole but not when only using --onefile. However, this issue was soon solved by creating an exception.
Here are the imports I use:
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
解决方案
The answer provided above by ThePyGuy has solved the issue. Adding hiddenimports=['pyperclip']
in the spec file was enough to prevent the error from occuring and the program ran fine to the extent that I tested it.
推荐阅读
- python - Django:如何在生产中设置新的静态路径?
- javascript - 递归 for 循环上下文中的 NaN
- c++ - MongoDb/mongocxx update_one 和 find_one 极慢
- javascript - 如何获取单元格值(来自 Google 表单的 Sheet1,来自公式的 Sheet2)到谷歌文档模板
- python - PyCall 接收 Numpy 并转换为本机类型元素
- .net - Blazor System.Net.Sockets.SocketException
- java - java正则表达式添加斜杠
- python - 用于监视文件系统更改的 Python 程序
- python - 在 Pandas 中操作数据
- kubernetes - kube init:为控制平面节点写入 Crisocket 信息时出错:等待条件超时