Skip to content

Commit d1a7159

Browse files
committed
fix missing Qt plugin on macOS
1 parent 5826210 commit d1a7159

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

cv2/__init__.py

+7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
import importlib
2+
import os
3+
import sys
24

35
from .cv2 import *
46
from .data import *
57

68
# wildcard import above does not import "private" variables like __version__
79
# this makes them available
810
globals().update(importlib.import_module('cv2.cv2').__dict__)
11+
12+
if sys.platform == 'darwin':
13+
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = os.path.join(
14+
os.path.dirname(os.path.abspath(__file__)), 'qt', 'plugins'
15+
)

patches/patchQtPlugins

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
diff --git a/opencv/CMakeLists.txt b/opencv/CMakeLists.txt
2+
index 8ccad4d03a..0d5e2a79e9 100644
3+
--- a/opencv/CMakeLists.txt
4+
+++ b/opencv/CMakeLists.txt
5+
@@ -1164,6 +1164,7 @@ if(WITH_QT OR HAVE_QT)
6+
if(HAVE_QT5)
7+
status(" QT:" "YES (ver ${Qt5Core_VERSION_STRING})")
8+
status(" QT OpenGL support:" HAVE_QT_OPENGL THEN "YES (${Qt5OpenGL_LIBRARIES} ${Qt5OpenGL_VERSION_STRING})" ELSE NO)
9+
+ install(DIRECTORY ${Qt5_DIR}/../../../plugins DESTINATION lib/qt)
10+
elseif(HAVE_QT)
11+
status(" QT:" "YES (ver ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH} ${QT_EDITION})")
12+
status(" QT OpenGL support:" HAVE_QT_OPENGL THEN "YES (${QT_QTOPENGL_LIBRARY})" ELSE NO)

setup.py

+2
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ def main():
128128

129129
if sys.platform == 'darwin' and not build_headless:
130130
cmake_args.append("-DWITH_QT=5")
131+
rearrange_cmake_output_data['cv2.qt.plugins.platforms'] = [(r'lib/qt/plugins/platforms/libqcocoa\.dylib')]
131132

132133
if build_headless:
133134
# it seems that cocoa cannot be disabled so on macOS the package is not truly headless
@@ -144,6 +145,7 @@ def main():
144145
# https://github.com/skvark/opencv-python/issues/21
145146
cmake_args.append("-DCMAKE_CXX_FLAGS=-stdlib=libc++")
146147
cmake_args.append("-DCMAKE_OSX_DEPLOYMENT_TARGET:STRING=10.9")
148+
subprocess.check_call("patch -p1 < patches/patchQtPlugins", shell=True)
147149

148150
if sys.platform.startswith('linux'):
149151
cmake_args.append("-DWITH_IPP=OFF") # tests fail with IPP compiled with

0 commit comments

Comments
 (0)