2017-09-05 36 views
2

我希望捆綁一些Python代碼到一個分佈式應用程序(.app文件),但有麻煩越來越OpenCV的 PyQt5到應用程序中。 無論,在另一方面,做工精細。無法捆綁的OpenCV和PyQt5

我已經剝奪我所有的代碼和問題仍然存在。請參見下面的代碼示例:

# Works absolutely fine 
import cv2 
print("Hi there opencv v{0} user!".format(cv2.__version__)) 

# Works absolutely fine 
from PyQt5.QtCore import * 
print("Qt version {0}".format(QT_VERSION_STR)) 

# Does not work, see below 
import cv2 
from PyQt5.QtCore import * 
print("Qt version {0}".format(QT_VERSION_STR)) 
print("opencv version {0}".format(cv2.__version__)) 

並以「不行」,我的意思是它捆綁沒有錯誤(python3.5 -m pyinstaller samplecode.py),但不能執行。相反,該程序退出並返回一個錯誤:

Traceback (most recent call last): 
    File "/Users/*****/build/test.py", line 1, in <module> 
    import cv2 
    File "/Users/*****/build/PyInstaller/loader/pyimod03_importers.py", line 631, in exec_module 
    exec(bytecode, module.__dict__) 
    File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/cv2/__init__.py", line 9, in <module> 
    from .cv2 import * 
    File "/Users/*****/build/PyInstaller/loader/pyimod03_importers.py", line 714, in load_module 
    module = loader.load_module(fullname) 
ImportError: dlopen(/Users/*****/build/test/dist/test/cv2.cv2.so, 2): Symbol not found: __ZN10QByteArray11shared_nullE 
    Referenced from: /Users/*****/build/test/dist/test/QtTest 
    Expected in: /Users/*****/build/test/dist/test/QtCore 
in /Users/*****/build/test/dist/test/QtTest 
[20049] Failed to execute script test 

星星只是替換我的個人和項目文件夾名稱。

我試圖手動複製cv2.so文件,重命名它cv2.cv2.so並且將其放置在文件夾中。這產生了一個稍微不同的錯誤:

Traceback (most recent call last): 
    File "/Users/*****/build/test.py", line 1, in <module> 
    import cv2 
    File "/Users/*****/build/PyInstaller/loader/pyimod03_importers.py", line 631, in exec_module 
    exec(bytecode, module.__dict__) 
    File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/cv2/__init__.py", line 9, in <module> 
    from .cv2 import * 
    File "/Users/*****/build/PyInstaller/loader/pyimod03_importers.py", line 714, in load_module 
    module = loader.load_module(fullname) 
ImportError: dlopen(/Users/*****/build/test/dist/test/cv2.cv2.so, 2): Library not loaded: @loader_path/.dylibs/QtGui 
    Referenced from: /Users/*****/build/test/dist/test/cv2.cv2.so 
    Reason: image not found 

我也試過cx_freeze和py2app但不能讓這些來工作的。我最遠的有pyinstaller,所以我更喜歡使用這個發展似乎是最活躍的。

我運行MacOS的10.12,並紛紛轉載運行同一個操作系統上的另一個全新安裝的MacBook錯誤。我使用Python 3.5.4,5.9.1 PyQt的,OpenCV的3.3.0。對於PyInstaller我試過3.2.1和最新開發。

誰能幫助我瞭解和解決這個錯誤?

回答

0

我遇到(使用MacOS的10.11.6)試圖執行我的應用程序,這是我使用pyinstaller還內置當這些同樣的錯誤。我能夠通過自嘲的OpenCV和pyinstaller以下版本成功地解決我的問題:

pip install opencv-python == 3.1.0.4 
pip install pyinstaller == 3.3.1 

這不是一個令人滿意的解決方案,但它可能是值得一試,如果你還在這個問題掙扎。