1
0
Files
electrum/electrum/gui/qml/__init__.py
SomberNight 2c3c50a09b mac build: fix pyinstaller erroring due to not being able to import pyqt6
Not sure why this a problem in the mac build but not in the windows build...

Also not sure why this only came up now -- was working before.
(I changed a few things in prev commits re the build scripts but I can't see the cause)

```
34827 INFO: Processing module hooks...
34828 INFO: Loading module hook 'hook-cryptography.py' from '/Users/vagrant/electrum/contrib/osx/build-venv/lib/python3.10/site-packages/_pyinstaller_hooks_contrib/hooks/stdhooks'...
35932 INFO: Loading module hook 'hook-mnemonic.py' from '/Users/vagrant/electrum/contrib/osx/build-venv/lib/python3.10/site-packages/_pyinstaller_hooks_contrib/hooks/stdhooks'...
35937 INFO: Loading module hook 'hook-certifi.py' from '/Users/vagrant/electrum/contrib/osx/build-venv/lib/python3.10/site-packages/_pyinstaller_hooks_contrib/hooks/stdhooks'...
35939 INFO: Loading module hook 'hook-dns.rdata.py' from '/Users/vagrant/electrum/contrib/osx/build-venv/lib/python3.10/site-packages/_pyinstaller_hooks_contrib/hooks/stdhooks'...
36502 INFO: Loading module hook 'hook-usb1.py' from '/Users/vagrant/electrum/contrib/osx/build-venv/lib/python3.10/site-packages/usb1/__pyinstaller'...
36503 INFO: --- libusb1 pyinstaller hook ---
36504 INFO: Added libusb binaries: []
36505 INFO: Loading module hook 'hook-sqlite3.py' from '/Users/vagrant/electrum/contrib/osx/build-venv/lib/python3.10/site-packages/PyInstaller/hooks'...
36932 INFO: Loading module hook 'hook-pkg_resources.py' from '/Users/vagrant/electrum/contrib/osx/build-venv/lib/python3.10/site-packages/PyInstaller/hooks'...
38303 INFO: Loading module hook 'hook-PyQt5.py' from '/Users/vagrant/electrum/contrib/osx/build-venv/lib/python3.10/site-packages/PyInstaller/hooks'...
38584 WARNING: Hidden import "sip" not found!
38586 INFO: Loading module hook 'hook-xml.etree.cElementTree.py' from '/Users/vagrant/electrum/contrib/osx/build-venv/lib/python3.10/site-packages/PyInstaller/hooks'...
38587 INFO: Loading module hook 'hook-lib2to3.py' from '/Users/vagrant/electrum/contrib/osx/build-venv/lib/python3.10/site-packages/PyInstaller/hooks'...
38678 INFO: Loading module hook 'hook-_tkinter.py' from '/Users/vagrant/electrum/contrib/osx/build-venv/lib/python3.10/site-packages/PyInstaller/hooks'...
39005 INFO: checking Tree
39006 INFO: Building Tree because Tree-00.toc is non existent
39006 INFO: Building Tree Tree-00.toc
39021 INFO: checking Tree
39022 INFO: Building Tree because Tree-01.toc is non existent
39022 INFO: Building Tree Tree-01.toc
39157 INFO: checking Tree
39158 INFO: Building Tree because Tree-02.toc is non existent
39158 INFO: Building Tree Tree-02.toc
39165 INFO: Loading module hook 'hook-encodings.py' from '/Users/vagrant/electrum/contrib/osx/build-venv/lib/python3.10/site-packages/PyInstaller/hooks'...
39568 INFO: Loading module hook 'hook-distutils.util.py' from '/Users/vagrant/electrum/contrib/osx/build-venv/lib/python3.10/site-packages/PyInstaller/hooks'...
39586 INFO: Loading module hook 'hook-platform.py' from '/Users/vagrant/electrum/contrib/osx/build-venv/lib/python3.10/site-packages/PyInstaller/hooks'...
39587 INFO: Loading module hook 'hook-PyQt5.QtGui.py' from '/Users/vagrant/electrum/contrib/osx/build-venv/lib/python3.10/site-packages/PyInstaller/hooks'...
39734 INFO: Loading module hook 'hook-PyQt5.QtPrintSupport.py' from '/Users/vagrant/electrum/contrib/osx/build-venv/lib/python3.10/site-packages/PyInstaller/hooks'...
39984 INFO: Loading module hook 'hook-PyQt5.QtMultimedia.py' from '/Users/vagrant/electrum/contrib/osx/build-venv/lib/python3.10/site-packages/PyInstaller/hooks'...
40164 INFO: Loading module hook 'hook-packaging.py' from '/Users/vagrant/electrum/contrib/osx/build-venv/lib/python3.10/site-packages/PyInstaller/hooks'...
40165 INFO: Loading module hook 'hook-pickle.py' from '/Users/vagrant/electrum/contrib/osx/build-venv/lib/python3.10/site-packages/PyInstaller/hooks'...
40187 INFO: Loading module hook 'hook-heapq.py' from '/Users/vagrant/electrum/contrib/osx/build-venv/lib/python3.10/site-packages/PyInstaller/hooks'...
40192 INFO: Loading module hook 'hook-difflib.py' from '/Users/vagrant/electrum/contrib/osx/build-venv/lib/python3.10/site-packages/PyInstaller/hooks'...
40196 INFO: Loading module hook 'hook-PyQt5.QtWidgets.py' from '/Users/vagrant/electrum/contrib/osx/build-venv/lib/python3.10/site-packages/PyInstaller/hooks'...
40361 INFO: Loading module hook 'hook-multiprocessing.util.py' from '/Users/vagrant/electrum/contrib/osx/build-venv/lib/python3.10/site-packages/PyInstaller/hooks'...
40382 INFO: Loading module hook 'hook-sysconfig.py' from '/Users/vagrant/electrum/contrib/osx/build-venv/lib/python3.10/site-packages/PyInstaller/hooks'...
40421 INFO: Loading module hook 'hook-PyQt5.QtNetwork.py' from '/Users/vagrant/electrum/contrib/osx/build-venv/lib/python3.10/site-packages/PyInstaller/hooks'...
40545 INFO: Loading module hook 'hook-xml.py' from '/Users/vagrant/electrum/contrib/osx/build-venv/lib/python3.10/site-packages/PyInstaller/hooks'...
40691 INFO: Loading module hook 'hook-distutils.py' from '/Users/vagrant/electrum/contrib/osx/build-venv/lib/python3.10/site-packages/PyInstaller/hooks'...
40692 INFO: Loading module hook 'hook-PyQt5.QtCore.py' from '/Users/vagrant/electrum/contrib/osx/build-venv/lib/python3.10/site-packages/PyInstaller/hooks'...
40903 INFO: Looking for ctypes DLLs
40987 WARNING: Library Cfgmgr32 required via ctypes not found
40992 WARNING: Library setupapi required via ctypes not found
40994 WARNING: Library Advapi32 required via ctypes not found
40996 WARNING: Ignoring /System/Library/Frameworks/IOKit.framework/IOKit imported from /Users/vagrant/electrum/contrib/osx/build-venv/lib/python3.10/site-packages/serial/tools/list_ports_osx.py - only basenames are supported with ctypes imports!
40996 WARNING: Ignoring /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation imported from /Users/vagrant/electrum/contrib/osx/build-venv/lib/python3.10/site-packages/serial/tools/list_ports_osx.py - only basenames are supported with ctypes imports!
41028 INFO: Analyzing run-time hooks ...
41041 INFO: Including run-time hook '/Users/vagrant/electrum/contrib/osx/build-venv/lib/python3.10/site-packages/PyInstaller/hooks/rthooks/pyi_rth_pyqt5.py'
41043 INFO: Including run-time hook '/Users/vagrant/electrum/contrib/osx/build-venv/lib/python3.10/site-packages/PyInstaller/hooks/rthooks/pyi_rth_pkgutil.py'
41047 INFO: Including run-time hook '/Users/vagrant/electrum/contrib/osx/build-venv/lib/python3.10/site-packages/PyInstaller/hooks/rthooks/pyi_rth_inspect.py'
41049 INFO: Including run-time hook '/Users/vagrant/electrum/contrib/osx/build-venv/lib/python3.10/site-packages/PyInstaller/hooks/rthooks/pyi_rth_subprocess.py'
41051 INFO: Including run-time hook '/Users/vagrant/electrum/contrib/osx/build-venv/lib/python3.10/site-packages/PyInstaller/hooks/rthooks/pyi_rth_multiprocessing.py'
41055 INFO: Including run-time hook '/Users/vagrant/electrum/contrib/osx/build-venv/lib/python3.10/site-packages/PyInstaller/hooks/rthooks/pyi_rth_pkgres.py'
41140 INFO: Looking for dynamic libraries
719 INFO: gettext setting initial language to None
Traceback (most recent call last):
  File "/Users/vagrant/electrum/contrib/osx/build-venv/bin/pyinstaller", line 8, in <module>
    sys.exit(run())
  File "/Users/vagrant/electrum/contrib/osx/build-venv/lib/python3.10/site-packages/PyInstaller/__main__.py", line 178, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "/Users/vagrant/electrum/contrib/osx/build-venv/lib/python3.10/site-packages/PyInstaller/__main__.py", line 59, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "/Users/vagrant/electrum/contrib/osx/build-venv/lib/python3.10/site-packages/PyInstaller/building/build_main.py", line 934, in main
    build(specfile, distpath, workpath, clean_build)
  File "/Users/vagrant/electrum/contrib/osx/build-venv/lib/python3.10/site-packages/PyInstaller/building/build_main.py", line 856, in build
    exec(code, spec_namespace)
  File "contrib/osx/osx.spec", line 48, in <module>
    a = Analysis([electrum+ MAIN_SCRIPT,
  File "/Users/vagrant/electrum/contrib/osx/build-venv/lib/python3.10/site-packages/PyInstaller/building/build_main.py", line 381, in __init__
    self.__postinit__()
  File "/Users/vagrant/electrum/contrib/osx/build-venv/lib/python3.10/site-packages/PyInstaller/building/datastruct.py", line 173, in __postinit__
    self.assemble()
  File "/Users/vagrant/electrum/contrib/osx/build-venv/lib/python3.10/site-packages/PyInstaller/building/build_main.py", line 660, in assemble
    isolated.call(find_binary_dependencies, list(self.binaries), self.binding_redirects, collected_packages)
  File "/Users/vagrant/electrum/contrib/osx/build-venv/lib/python3.10/site-packages/PyInstaller/isolated/_parent.py", line 238, in call
    return isolated.call(function, *args, **kwargs)
  File "/Users/vagrant/electrum/contrib/osx/build-venv/lib/python3.10/site-packages/PyInstaller/isolated/_parent.py", line 176, in call
    raise RuntimeError(f"Child process call to {function.__name__}() failed with:\n" + output)
RuntimeError: Child process call to find_binary_dependencies() failed with:
  File "/Users/vagrant/electrum/electrum/gui/qml/__init__.py", line 8, in <module>
    import PyQt6
ModuleNotFoundError: No module named 'PyQt6'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/vagrant/electrum/contrib/osx/build-venv/lib/python3.10/site-packages/PyInstaller/isolated/_child.py", line 63, in run_next_command
    output = function(*args, **kwargs)
  File "/Users/vagrant/electrum/contrib/osx/build-venv/lib/python3.10/site-packages/PyInstaller/building/build_main.py", line 157, in find_binary_dependencies
    __import__(package)
  File "/Users/vagrant/electrum/electrum/gui/qml/__init__.py", line 10, in <module>
    sys.exit("Error: Could not import PyQt6. On Linux systems, you may try 'sudo apt-get install python3-pyqt6'")
SystemExit: Error: Could not import PyQt6. On Linux systems, you may try 'sudo apt-get install python3-pyqt6'
🗯 ERROR: Could not build binary
```
2023-11-30 13:43:57 +00:00

119 lines
4.0 KiB
Python

import os
import signal
import sys
import threading
from typing import TYPE_CHECKING
try:
import PyQt6
except Exception as e:
from electrum import GuiImportError
raise GuiImportError(
"Error: Could not import PyQt6. On Linux systems, "
"you may try 'sudo apt-get install python3-pyqt6'") from e
try:
import PyQt6.QtQml
except Exception as e:
from electrum import GuiImportError
raise GuiImportError(
"Error: Could not import PyQt6.QtQml. On Linux systems, "
"you may try 'sudo apt-get install python3-pyqt6.qtquick'") from e
from PyQt6.QtCore import (Qt, QCoreApplication, QLocale, QTranslator, QTimer, QT_VERSION_STR, PYQT_VERSION_STR)
from PyQt6.QtGui import QGuiApplication
sys._GUI_QT_VERSION = 6 # used by gui/common_qt
from electrum.i18n import _
from electrum.plugin import run_hook
from electrum.util import profiler
from electrum.logging import Logger
from electrum.gui import BaseElectrumGui
if TYPE_CHECKING:
from electrum.daemon import Daemon
from electrum.simple_config import SimpleConfig
from electrum.plugin import Plugins
from .qeapp import ElectrumQmlApplication, Exception_Hook
class ElectrumTranslator(QTranslator):
def __init__(self, parent=None):
super().__init__(parent)
def translate(self, context, source_text, disambiguation, n):
return _(source_text, context=context)
class ElectrumGui(BaseElectrumGui, Logger):
@profiler
def __init__(self, config: 'SimpleConfig', daemon: 'Daemon', plugins: 'Plugins'):
BaseElectrumGui.__init__(self, config=config, daemon=daemon, plugins=plugins)
Logger.__init__(self)
# uncomment to debug plugin and import tracing
# os.environ['QML_IMPORT_TRACE'] = '1'
# os.environ['QT_DEBUG_PLUGINS'] = '1'
os.environ['QT_ANDROID_DISABLE_ACCESSIBILITY'] = '1'
# set default locale to en_GB. This is for l10n (e.g. number formatting, number input etc),
# but not for i18n, which is handled by the Translator
# this can be removed once the backend wallet is fully l10n aware
QLocale.setDefault(QLocale('en_GB'))
self.logger.info(f"Qml GUI starting up... Qt={QT_VERSION_STR}, PyQt={PYQT_VERSION_STR}")
self.logger.info("CWD=%s" % os.getcwd())
# Uncomment this call to verify objects are being properly
# GC-ed when windows are closed
#network.add_jobs([DebugMem([Abstract_Wallet, SPV, Synchronizer,
# ElectrumWindow], interval=5)])
if hasattr(Qt, "AA_ShareOpenGLContexts"):
QCoreApplication.setAttribute(Qt.AA_ShareOpenGLContexts)
if hasattr(QGuiApplication, 'setDesktopFileName'):
QGuiApplication.setDesktopFileName('electrum.desktop')
if "QT_QUICK_CONTROLS_STYLE" not in os.environ:
os.environ["QT_QUICK_CONTROLS_STYLE"] = "Material"
self.gui_thread = threading.current_thread()
self.app = ElectrumQmlApplication(sys.argv, config=config, daemon=daemon, plugins=plugins)
self.translator = ElectrumTranslator()
self.app.installTranslator(self.translator)
# timer
self.timer = QTimer(self.app)
self.timer.setSingleShot(False)
self.timer.setInterval(500) # msec
self.timer.timeout.connect(lambda: None) # periodically enter python scope
# hook for crash reporter
Exception_Hook.maybe_setup(config=config, slot=self.app.appController.crash)
# Initialize any QML plugins
run_hook('init_qml', self.app)
self.app.engine.load('electrum/gui/qml/components/main.qml')
def close(self):
self.app.quit()
def main(self):
if not self.app._valid:
return
self.timer.start()
signal.signal(signal.SIGINT, lambda *args: self._handle_sigint())
self.logger.info('Entering main loop')
self.app.exec()
def _handle_sigint(self):
self.app.appController.wantClose = True
self.stop()
def stop(self):
self.logger.info('closing GUI')
self.app.quit()