I want to bundle some python code into a distributable application (.app file) but having trouble with getting opencv and PyQt5 into an application. Either, on the other hand, works fine.
I've stripped all my code and the problem persists. See the following code samples:
# 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__))
And by "not work", I mean that it bundles without errors (python3.5 -m pyinstaller samplecode.py
), but cannot be executed. Instead, the program quits and returns an error:
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
The stars just replace my personal and project folder names.
I tried manually copying the cv2.so file, renaming it to cv2.cv2.so and placing it in the folder. This produces the a slightly different error:
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
I've also tried cx_freeze and py2app but couldn't get these to work either. I got the furthest with pyinstaller and its development seems the most active so I prefer using this.
I'm running MacOS 10.12, and have reproduced the error on another clean-install MacBook running the same OS. I'm using Python 3.5.4, PyQt 5.9.1, OpenCV 3.3.0. For PyInstaller I've tried 3.2.1 and the most recent dev.
Can anyone help me understand and solve this error?