Repository: pyinstaller/pyinstaller

Issue:
Unable to find QtWebEngineCore (anaconda + macOS)
## When running pyinstaller to package my app, I am running into an issue with finding QtWebEngineCore.framework/Resources

### Context information (for bug reports)

* Output of `pyinstaller --version`: ```4.7```
* Version of Python: 3.8.5
* Platform: MacOS BigSur Intel, and MacOS Monterrey Apple Silicon
* How you installed Python: Conda


### Stacktrace / full error message


```
900 INFO: PyInstaller: 4.7
900 INFO: Python: 3.8.5 (conda)
910 INFO: Platform: macOS-10.16-x86_64-i386-64bit
911 INFO: wrote /Users/ricardoserrano-smith/Documents/GitHub/ConnectAdmin/downloadtool.spec
916 INFO: UPX is not available.
917 INFO: Extending PYTHONPATH with paths
['/Users/ricardoserrano-smith/Documents/GitHub/ConnectAdmin']
1115 INFO: checking Analysis
1116 INFO: Building Analysis because Analysis-00.toc is non existent
1116 INFO: Initializing module dependency graph...
1118 INFO: Caching module graph hooks...
1123 INFO: Analyzing base_library.zip ...
2940 INFO: Processing pre-find module path hook distutils from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks/pre_find_module_path/hook-distutils.py'.
2940 INFO: distutils: retargeting to non-venv dir '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8'
5048 INFO: Caching module dependency graph...
5152 INFO: running Analysis Analysis-00.toc
5155 INFO: Analyzing /Users/ricardoserrano-smith/Documents/GitHub/ConnectAdmin/downloadtool.py
9038 INFO: Processing pre-safe import module hook six.moves from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks/pre_safe_import_module/hook-six.moves.py'.
9654 INFO: Processing pre-find module path hook site from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks/pre_find_module_path/hook-site.py'.
9654 INFO: site: retargeting to fake-dir '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/fake-modules'
13860 INFO: Processing pre-safe import module hook urllib3.packages.six.moves from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks/pre_safe_import_module/hook-urllib3.packages.six.moves.py'.
25085 INFO: Processing module hooks...
25085 INFO: Loading module hook 'hook-zmq.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/_pyinstaller_hooks_contrib/hooks/stdhooks'...
26078 INFO: Loading module hook 'hook-parso.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/_pyinstaller_hooks_contrib/hooks/stdhooks'...
26083 INFO: Loading module hook 'hook-notebook.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/_pyinstaller_hooks_contrib/hooks/stdhooks'...
27076 INFO: Loading module hook 'hook-cryptography.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/_pyinstaller_hooks_contrib/hooks/stdhooks'...
27221 INFO: Loading module hook 'hook-jinja2.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/_pyinstaller_hooks_contrib/hooks/stdhooks'...
27235 INFO: Loading module hook 'hook-IPython.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/_pyinstaller_hooks_contrib/hooks/stdhooks'...
27539 INFO: Loading module hook 'hook-nbconvert.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/_pyinstaller_hooks_contrib/hooks/stdhooks'...
27568 INFO: Loading module hook 'hook-pycparser.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/_pyinstaller_hooks_contrib/hooks/stdhooks'...
27568 INFO: Loading module hook 'hook-jsonschema.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/_pyinstaller_hooks_contrib/hooks/stdhooks'...
27573 INFO: Loading module hook 'hook-jedi.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/_pyinstaller_hooks_contrib/hooks/stdhooks'...
27866 INFO: Loading module hook 'hook-certifi.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/_pyinstaller_hooks_contrib/hooks/stdhooks'...
27868 INFO: Loading module hook 'hook-docutils.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/_pyinstaller_hooks_contrib/hooks/stdhooks'...
29029 INFO: Loading module hook 'hook-pytest.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/_pyinstaller_hooks_contrib/hooks/stdhooks'...
29520 INFO: Loading module hook 'hook-nbformat.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/_pyinstaller_hooks_contrib/hooks/stdhooks'...
29533 INFO: Loading module hook 'hook-sqlite3.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
29575 INFO: Loading module hook 'hook-pkg_resources.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
30054 INFO: Processing pre-safe import module hook win32com from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/_pyinstaller_hooks_contrib/hooks/pre_safe_import_module/hook-win32com.py'.
30058 WARNING: Hidden import "pkg_resources.py2_warn" not found!
30069 WARNING: Hidden import "pkg_resources.markers" not found!
30072 INFO: Loading module hook 'hook-babel.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
30119 INFO: Loading module hook 'hook-PyQt5.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
32391 WARNING: Hidden import "PyQt5.sip" not found!
32391 INFO: Loading module hook 'hook-scipy.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
32392 INFO: Loading module hook 'hook-xml.etree.cElementTree.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
32393 INFO: Loading module hook 'hook-pytz.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
32441 INFO: Loading module hook 'hook-sphinx.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
35308 INFO: Loading module hook 'hook-lib2to3.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
35323 INFO: Loading module hook 'hook-_tkinter.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
35421 INFO: checking Tree
35426 INFO: checking Tree
35476 INFO: checking Tree
35478 INFO: Loading module hook 'hook-encodings.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
35523 INFO: Loading module hook 'hook-PIL.ImageFilter.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
35531 INFO: Loading module hook 'hook-distutils.util.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
35534 INFO: Loading module hook 'hook-PIL.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
35536 INFO: Import to be excluded not found: 'PyQt6'
35539 INFO: Import to be excluded not found: 'PySide6'
35541 INFO: Loading module hook 'hook-setuptools.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
36042 INFO: Loading module hook 'hook-zope.interface.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
36046 INFO: Loading module hook 'hook-gevent.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
36245 INFO: Determining a mapping of distributions to packages...
71080 WARNING: Unable to find package for requirement zope.event from package gevent.
71080 WARNING: Unable to find package for requirement greenlet from package gevent.
71080 WARNING: Unable to find package for requirement zope.interface from package gevent.
71080 INFO: Packages required by gevent:
['setuptools']
71801 INFO: Loading module hook 'hook-matplotlib.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
72300 INFO: Loading module hook 'hook-xml.dom.domreg.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
72300 INFO: Loading module hook 'hook-PyQt5.QtGui.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
72315 INFO: Loading module hook 'hook-PIL.Image.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
72636 INFO: Loading module hook 'hook-PyQt5.Qt.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
72639 INFO: Loading module hook 'hook-packaging.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
72639 INFO: Loading module hook 'hook-pickle.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
72643 INFO: Loading module hook 'hook-PyQt5.QtSql.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
72662 INFO: Loading module hook 'hook-matplotlib.backends.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
73367 INFO:   Matplotlib backend "GTK3Agg": ignored
    backend Gtk3Agg requires cairo
73719 INFO:   Matplotlib backend "GTK3Cairo": ignored
    cairo backend requires that pycairo>=1.11.0 or cairocffiis installed
74196 INFO:   Matplotlib backend "MacOSX": added
74868 INFO:   Matplotlib backend "nbAgg": added
<string>:12: MatplotlibDeprecationWarning: 
The matplotlib.backends.backend_qt4agg backend was deprecated in Matplotlib 3.3 and will be removed two minor releases later.
75331 INFO:   Matplotlib backend "Qt4Agg": added
75683 INFO:   Matplotlib backend "Qt4Cairo": ignored
    cairo backend requires that pycairo>=1.11.0 or cairocffiis installed
76121 INFO:   Matplotlib backend "Qt5Agg": added
76471 INFO:   Matplotlib backend "Qt5Cairo": ignored
    cairo backend requires that pycairo>=1.11.0 or cairocffiis installed
76932 INFO:   Matplotlib backend "TkAgg": added
77383 INFO:   Matplotlib backend "TkCairo": ignored
    cairo backend requires that pycairo>=1.11.0 or cairocffiis installed
77832 INFO:   Matplotlib backend "WebAgg": added
78273 INFO:   Matplotlib backend "WX": ignored
    No module named 'wx'
78624 INFO:   Matplotlib backend "WXAgg": ignored
    No module named 'wx'
78975 INFO:   Matplotlib backend "WXCairo": ignored
    No module named 'wx'
79365 INFO:   Matplotlib backend "agg": added
79720 INFO:   Matplotlib backend "cairo": ignored
    cairo backend requires that pycairo>=1.11.0 or cairocffiis installed
80171 INFO:   Matplotlib backend "pdf": added
80617 INFO:   Matplotlib backend "pgf": added
81006 INFO:   Matplotlib backend "ps": added
81398 INFO:   Matplotlib backend "svg": added
81839 INFO:   Matplotlib backend "template": added
82156 INFO: Loading module hook 'hook-importlib_metadata.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
82157 INFO: Loading module hook 'hook-PyQt5.QtQml.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
82197 INFO: Loading module hook 'hook-heapq.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
82201 INFO: Loading module hook 'hook-PyQt5.QtQuickWidgets.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
82230 INFO: Loading module hook 'hook-difflib.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
82233 INFO: Loading module hook 'hook-PyQt5.QtPositioning.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
82242 INFO: Loading module hook 'hook-PyQt5.QtWidgets.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
82259 INFO: Loading module hook 'hook-multiprocessing.util.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
82263 INFO: Loading module hook 'hook-sysconfig.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
82267 INFO: Loading module hook 'hook-wcwidth.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
82269 INFO: Loading module hook 'hook-PyQt5.QtNetwork.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
82276 INFO: Loading module hook 'hook-xml.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
82277 INFO: Loading module hook 'hook-numpy.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
82349 INFO: Import to be excluded not found: 'f2py'
82366 INFO: Loading module hook 'hook-PyQt5.QtTest.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
82382 INFO: Loading module hook 'hook-distutils.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
82382 INFO: Loading module hook 'hook-numpy._pytesttester.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
82386 INFO: Loading module hook 'hook-PyQt5.QtCore.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
82390 INFO: Loading module hook 'hook-PyQt5.QtSvg.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
82405 INFO: Loading module hook 'hook-pygments.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
83547 INFO: Loading module hook 'hook-lxml.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/_pyinstaller_hooks_contrib/hooks/stdhooks'...
84567 INFO: Loading module hook 'hook-lxml.etree.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/_pyinstaller_hooks_contrib/hooks/stdhooks'...
84567 INFO: Loading module hook 'hook-PyQt5.QtXml.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
84577 INFO: Loading module hook 'hook-PyQt5.QtSerialPort.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
84587 INFO: Loading module hook 'hook-PIL.SpiderImagePlugin.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
84591 INFO: Loading module hook 'hook-PyQt5.QtLocation.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
84618 INFO: Loading module hook 'hook-setuptools.msvc.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
84622 INFO: Loading module hook 'hook-PyQt5.QtHelp.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
84645 INFO: Loading module hook 'hook-PyQt5.QtQuick.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
84658 INFO: Loading module hook 'hook-PyQt5.QtWebEngineWidgets.py' from '/Users/ricardoserrano-smith/opt/anaconda3/lib/python3.8/site-packages/PyInstaller/hooks'...
Unable to find "/Users/ricardoserrano-smith/opt/anaconda3/lib/QtWebEngineCore.framework/Resources" when adding binary and data files.
```



Discussion:
Yeah, our QtWebEngine hooks on macOS currently do not support Anaconda, because they expect a `.framework`-based layout, whereas conda uses `dylib`-based one, which is close(r) to what we expect on Windows and Linux... Marking this as a feature request.

Resolving patch:
diff --git a/PyInstaller/hooks/rthooks/pyi_rth_pyqt5webengine.py b/PyInstaller/hooks/rthooks/pyi_rth_pyqt5webengine.py
--- a/PyInstaller/hooks/rthooks/pyi_rth_pyqt5webengine.py
+++ b/PyInstaller/hooks/rthooks/pyi_rth_pyqt5webengine.py
@@ -19,9 +19,14 @@
     if not os.path.isdir(pyqt_path):
         # ... and fall back to the older version
         pyqt_path = os.path.join(sys._MEIPASS, 'PyQt5', 'Qt')
-    os.environ['QTWEBENGINEPROCESS_PATH'] = os.path.normpath(
+
+    # If QtWebEngineProcess was collected from a framework-based Qt build, we need to set QTWEBENGINEPROCESS_PATH.
+    # If not (a dylib-based build; Anaconda on macOS), it should be found automatically, same as on other OSes.
+    process_path = os.path.normpath(
         os.path.join(
             pyqt_path, 'lib', 'QtWebEngineCore.framework', 'Helpers', 'QtWebEngineProcess.app', 'Contents', 'MacOS',
             'QtWebEngineProcess'
         )
     )
+    if os.path.exists(process_path):
+        os.environ['QTWEBENGINEPROCESS_PATH'] = process_path
diff --git a/PyInstaller/hooks/rthooks/pyi_rth_pyside2webengine.py b/PyInstaller/hooks/rthooks/pyi_rth_pyside2webengine.py
--- a/PyInstaller/hooks/rthooks/pyi_rth_pyside2webengine.py
+++ b/PyInstaller/hooks/rthooks/pyi_rth_pyside2webengine.py
@@ -13,9 +13,13 @@
 import sys
 
 if sys.platform == 'darwin':
-    os.environ['QTWEBENGINEPROCESS_PATH'] = os.path.normpath(
+    # If QtWebEngineProcess was collected from a framework-based Qt build, we need to set QTWEBENGINEPROCESS_PATH.
+    # If not (a dylib-based build; Anaconda on macOS), it should be found automatically, same as on other OSes.
+    process_path = os.path.normpath(
         os.path.join(
             sys._MEIPASS, 'PySide2', 'Qt', 'lib', 'QtWebEngineCore.framework', 'Helpers', 'QtWebEngineProcess.app',
             'Contents', 'MacOS', 'QtWebEngineProcess'
         )
     )
+    if os.path.exists(process_path):
+        os.environ['QTWEBENGINEPROCESS_PATH'] = process_path
diff --git a/PyInstaller/utils/hooks/qt.py b/PyInstaller/utils/hooks/qt.py
--- a/PyInstaller/utils/hooks/qt.py
+++ b/PyInstaller/utils/hooks/qt.py
@@ -708,7 +708,16 @@ def get_qt_webengine_binaries_and_data_files(qt_library_info):
     # qt_library_info.qt_rel_dir)
     rel_data_path = qt_library_info.qt_rel_dir
 
+    is_macos_framework = False
     if compat.is_darwin:
+        # Determine if we are dealing with a framework-based Qt build (e.g., PyPI wheels) or a dylib-based one
+        # (e.g., Anaconda). The former requires special handling, while the latter is handled in the same way as
+        # Windows and Linux builds.
+        is_macos_framework = os.path.exists(
+            os.path.join(qt_library_info.location['LibrariesPath'], 'QtWebEngineCore.framework')
+        )
+
+    if is_macos_framework:
         # On macOS, Qt shared libraries are provided in form of .framework bundles. However, PyInstaller collects shared
         # library from the bundle into top-level application directory, breaking the bundle structure.
         #
@@ -746,7 +755,7 @@ def get_qt_webengine_binaries_and_data_files(qt_library_info):
             )
         datas += [(os.path.join(data_path, 'lib', 'QtWebEngineCore.framework', 'Resources'), os.curdir)]
     else:
-        # Windows and linux
+        # Windows and linux (or Anaconda on macOS)
         locales = 'qtwebengine_locales'
         resources = 'resources'
 
@@ -767,7 +776,7 @@ def get_qt_webengine_binaries_and_data_files(qt_library_info):
             rel_data_path,
             os.path.relpath(qt_library_info.location['LibraryExecutablesPath'], qt_library_info.location['PrefixPath'])
         )
-        datas.append((os.path.join(qt_library_info.location['LibraryExecutablesPath'], 'QtWebEngineProcess*'), dest))
+        binaries.append((os.path.join(qt_library_info.location['LibraryExecutablesPath'], 'QtWebEngineProcess*'), dest))
 
     # Add Linux-specific libraries.
     if compat.is_linux:


Test patch: