我遇到了一个非常令人沮丧的错误,该错误发生在尝试运行由py2app生成的python应用程序(.app)时 - 在我的10.12.6 OS X笔记本电脑上。PyQt5 是使用 pip3 安装的,并且自问题发生以来已重新安装。这是完整的错误代码:
Last login: Mon Oct 23 00:14:00 on ttys001
/Users/development/Desktop/python_workspace/BasicEmail/dist/main.app/Contents/MacOS/main ; exit;
Zacharys-MacBook-Pro:~ development$/Users/development/Desktop/python_workspace/BasicEmail/dist/main.app/Contents/MacOS/main ; exit;
Traceback (most recent call last):
File "/Users/development/Desktop/python_workspace/BasicEmail/dist/main.app/Contents/Resources/__boot__.py", line 386, in <module>
_run()
File "/Users/development/Desktop/python_workspace/BasicEmail/dist/main.app/Contents/Resources/__boot__.py", line 370, in _run
exec(compile(source, path, 'exec'), globals(), globals())
File "/Users/development/Desktop/python_workspace/BasicEmail/dist/main.app/Contents/Resources/main.py", line 4, in <module>
from sheet import Sheet
File "sheet.pyc", line 8, in <module>
File "PyQt5/QtWidgets.pyc", line 14, in <module>
File "PyQt5/QtWidgets.pyc", line 10, in __load
File "imp.pyc", line 342, in load_dynamic
ImportError: dlopen(/Users/development/Desktop/python_workspace/BasicEmail/dist/main.app/Contents/Resources/lib/python3.6/lib-dynload/PyQt5/QtWidgets.so, 2):
Library not loaded: @rpath/QtWidgets.framework/Versions/5/QtWidgets
Referenced from: /Users/development/Desktop/python_workspace/BasicEmail/dist/main.app/Contents/Resources/lib/python3.6/lib-dynload/PyQt5/QtWidgets.so
Reason: image not found
2017-10-23 00:19:19.853 main[31651:3648399] main Error`
我的 sheet.py 代码。我的应用程序的第一个视图:
import sys
import os
import re
import io
import csv
#from PyQt5 import QtWidgets, QtCore, QtGui
import PyQt5
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
class Sheet(QWidget):
buttonClicked = pyqtSignal()
email_list = []
#company_list = []
def __init__(self,r,c):
super().__init__()
self.init_ui(r,c)
def init_ui(self,r,c):
self.v_layout = QVBoxLayout()
self.h_layout = QHBoxLayout()
self.sheet = QTableWidget()
self.sheet.setRowCount(r)
self.sheet.setColumnCount(c)
item = QTableWidgetItem('Upload a CSV file with emails.')
self.sheet.setItem(0, 0, item)
self.sheet.resizeRowsToContents()
self.sheet.verticalHeader().setDefaultSectionSize(50)
width = 200
self.open_button = TemplateButton(QPixmap('res/open-folder.png'))
self.open_button.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
self.continue_button = TemplateButton(QPixmap('res/forward-arrow.png'))
self.continue_button.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
self.file_path = None
self.open_button.clicked.connect(lambda: self.open_click(self.open_button,"Open",self.sheet))
self.continue_button.clicked.connect(lambda: self.continue_click(self.continue_button,"Continue"))
self.v_layout.addWidget(self.sheet)
self.h_layout.addWidget(self.open_button)
self.h_layout.addWidget(self.continue_button)
self.v_layout.addLayout(self.h_layout)
self.setLayout(self.v_layout)
self.setWindowTitle("EMAIL")
self.show()
主要我怀疑同一个人会打电话给我的其他人:
import sys
import os
import io
from sheet import Sheet
from email_list import EmailList
from construct import ConstructEmail
from construct import NewTemplateDialog, ConfirmDialog
from template_list import TemplateList, TemplateEdit
from settings import Settings
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
我已经找到了问题的答案。在捆绑应用程序时,您必须包含标志 --packages=PyQt5
这对我有用:
python setup.py py2app --packages=PyQt5