Compiling Anki 2.1.38 for Raspberry Pi 4/400 with Ubuntu 20.10 (architecture: aarch64)

I recently got a Rasbperry Pi 400 and I’ve been having trouble compiling for this system

./run outputs the following

WARNING: Download from https://mirror.bazel.build/nodejs.org/dist/v12.13.0/node-v12.13.0-linux-arm64.tar.xz failed: class com.google.devtools.build.lib.bazel.repository.downloader.UnrecoverableHttpException GET returned 404 Not Found
INFO: Build option --compilation_mode has changed, discarding analysis cache.
ERROR: /home/nasfarley88/.cache/bazel/_bazel_nasfarley88/68baae049f42cc47f3275eca21baf2a5/external/com_google_protobuf/BUILD.bazel:2:6: Configurable attribute "actual" doesn't match this configuration (would a default condition help?).
Conditions checked:
 //platforms:windows_x86_64
 //platforms:macos_x86_64
 //platforms:linux_x86_64
INFO: Repository rust_linux_aarch64 instantiated at:
  /home/nasfarley88/.local/opt/anki-git/WORKSPACE:14:11: in <toplevel>
  /home/nasfarley88/.local/opt/anki-git/defs.bzl:20:22: in setup_deps
  /home/nasfarley88/.cache/bazel/_bazel_nasfarley88/68baae049f42cc47f3275eca21baf2a5/external/io_bazel_rules_rust/rust/repositories.bzl:86:24: in rust_repositories
  /home/nasfarley88/.cache/bazel/_bazel_nasfarley88/68baae049f42cc47f3275eca21baf2a5/external/io_bazel_rules_rust/rust/repositories.bzl:718:30: in rust_repository_set
Repository rule rust_toolchain_repository defined at:
  /home/nasfarley88/.cache/bazel/_bazel_nasfarley88/68baae049f42cc47f3275eca21baf2a5/external/io_bazel_rules_rust/rust/repositories.bzl:617:44: in <toplevel>
ERROR: Analysis of target '//qt:runanki' failed; build aborted: /home/nasfarley88/.cache/bazel/_bazel_nasfarley88/68baae049f42cc47f3275eca21baf2a5/external/com_google_protobuf/BUILD.bazel:2:6: Configurable attribute "actual" doesn't match this configuration (would a default condition help?).
Conditions checked:
 //platforms:windows_x86_64
 //platforms:macos_x86_64
 //platforms:linux_x86_64
INFO: Elapsed time: 9.843s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (3 packages loaded, 438 targets configured)
FAILED: Build did NOT complete successfully (3 packages loaded, 438 targets configured)
    Fetching @pyqt5; fetching 8s
    Fetching @pypi__38__urllib3_1_26_2; fetching

My instincts tell me that compiling for this system should be possible (pyqt5 seems generally available in the aarch64 repos in Ubuntu 20.10) but I don’t have enough experience with bazel to know where to start!

I’m a reguarly user of CMake and Make professionally so more than happy to get my hands dirty, just wondering if anyone has any pointers on how to enable aarch64 support?

The latest git should get you a bit further. The ./run command depends on PyQt5 from PyPi. Since there don’t appear to be arm64 wheels of PyQt, you may need to use ./scripts/build instead, and then install the wheels into an environment that has PyQt5 available. Please let me know how you go.

You’ll likely also need to compile orjson or patch it out

Thanks, I’ll give those things a go and report back

Thanks for the help so far! Initially, the building timed out, so I added a higher timeout in the _execute function in pip/pyqt5/defs.bzl

def _execute(repository_ctx, arguments, quiet = False):
    pip_vendor = str(repository_ctx.path(pip_vendor_label).dirname)
    return repository_ctx.execute(arguments, environment = {
        "PYTHONPATH": pip_vendor,
    }, timeout = 9000000, quiet = quiet)

After that, moved on to a new error (this log is from attempting to rebuild so ignore the build time):

nasfarley88@wesley /m/u/anki-git (master)> ./scripts/build
INFO: Repository pyqt5 instantiated at:
  /media/usb/anki-git/WORKSPACE:14:11: in <toplevel>
  /media/usb/anki-git/defs.bzl:39:18: in setup_deps
Repository rule install_pyqt5 defined at:
  /media/usb/anki-git/pip/pyqt5/defs.bzl:26:32: in <toplevel>
ERROR: An error occurred during the fetch of repository 'pyqt5':
   Traceback (most recent call last):
        File "/media/usb/anki-git/pip/pyqt5/defs.bzl", line 24, column 13, in _install_pyqt5_impl
                fail("failed: %s (%s)" % (result.stdout, result.stderr))
Error in fail: failed: Processing /media/usb/anki-git/nasfarley88-cache/pip/wheels/8d/ae/57/40547abf06792b4af4a7d6459061b340b48ed0f4313c10078b/PyQt5-5.15.2-cp35.cp36.cp37.cp38.cp39-abi3-manylinux2014_aarch64.whl
Installing collected packages: pyqt5
Successfully installed pyqt5-5.15.2
Collecting pyqtwebengine==5.15.2
  Using cached PyQtWebEngine-5.15.2.tar.gz (48 kB)
  Installing build dependencies: started
  Installing build dependencies: finished with status 'done'
  Getting requirements to build wheel: started
  Getting requirements to build wheel: finished with status 'done'
    Preparing wheel metadata: started
    Preparing wheel metadata: finished with status 'error'
 (    ERROR: Command errored out with exit status 1:
     command: /media/usb/anki-git/nasfarley88-cache/bazel/_bazel_nasfarley88/c06b69b14aa56b339da9c44f7a52da1e/external/python/python /media/usb/anki-git/nasfarley88-cache/bazel/_bazel_nasfarley88/c06b69b14aa56b3
39da9c44f7a52da1e/external/com_github_ali5h_rules_pip/third_party/py/pip/_vendor/pep517/_in_process.py prepare_metadata_for_build_wheel /tmp/tmpl99wxtjo
         cwd: /tmp/pip-install-knv2a94a/pyqtwebengine
    Complete output (6 lines):
    Querying qmake about your Qt installation...
    /usr/bin/qmake -query
    These bindings will be built: QtWebEngineCore, QtWebEngine, QtWebEngineWidgets.
    Generating the QtWebEngineCore bindings...
    _in_process.py: Unable to find file "QtCore/QtCoremod.sip"

    ----------------------------------------
ERROR: Command errored out with exit status 1: /media/usb/anki-git/nasfarley88-cache/bazel/_bazel_nasfarley88/c06b69b14aa56b339da9c44f7a52da1e/external/python/python /media/usb/anki-git/nasfarley88-cache/bazel/_
bazel_nasfarley88/c06b69b14aa56b339da9c44f7a52da1e/external/com_github_ali5h_rules_pip/third_party/py/pip/_vendor/pep517/_in_process.py prepare_metadata_for_build_wheel /tmp/tmpl99wxtjo Check the logs for full c
ommand output.
Traceback (most recent call last):
  File "/media/usb/anki-git/pip/pyqt5/install_pyqt5.py", line 163, in <module>
    main()
  File "/media/usb/anki-git/pip/pyqt5/install_pyqt5.py", line 119, in main
    _pkg = install_package(with_version, folder, [])
  File "/media/usb/anki-git/pip/pyqt5/install_pyqt5.py", line 54, in install_package
    dist_info = glob.glob(os.path.join(directory, "*.dist-info"))[0]
IndexError: list index out of range
)
ERROR: /media/usb/anki-git/qt/aqt/BUILD.bazel:74:11: //qt/aqt:aqt_with_data depends on @pyqt5//:pkg in repository @pyqt5 which failed to fetch. no such package '@pyqt5//': failed: Processing /media/usb/anki-git/
nasfarley88-cache/pip/wheels/8d/ae/57/40547abf06792b4af4a7d6459061b340b48ed0f4313c10078b/PyQt5-5.15.2-cp35.cp36.cp37.cp38.cp39-abi3-manylinux2014_aarch64.whl
Installing collected packages: pyqt5
Successfully installed pyqt5-5.15.2
Collecting pyqtwebengine==5.15.2
  Using cached PyQtWebEngine-5.15.2.tar.gz (48 kB)
  Installing build dependencies: started
  Installing build dependencies: finished with status 'done'
  Getting requirements to build wheel: started
  Getting requirements to build wheel: finished with status 'done'
    Preparing wheel metadata: started
    Preparing wheel metadata: finished with status 'error'
 (    ERROR: Command errored out with exit status 1:
     command: /media/usb/anki-git/nasfarley88-cache/bazel/_bazel_nasfarley88/c06b69b14aa56b339da9c44f7a52da1e/external/python/python /media/usb/anki-git/nasfarley88-cache/bazel/_bazel_nasfarley88/c06b69b14aa56b3
39da9c44f7a52da1e/external/com_github_ali5h_rules_pip/third_party/py/pip/_vendor/pep517/_in_process.py prepare_metadata_for_build_wheel /tmp/tmpl99wxtjo
         cwd: /tmp/pip-install-knv2a94a/pyqtwebengine
    Complete output (6 lines):
    Querying qmake about your Qt installation...
    /usr/bin/qmake -query
    These bindings will be built: QtWebEngineCore, QtWebEngine, QtWebEngineWidgets.
    Generating the QtWebEngineCore bindings...
    _in_process.py: Unable to find file "QtCore/QtCoremod.sip"

    ----------------------------------------
ERROR: Command errored out with exit status 1: /media/usb/anki-git/nasfarley88-cache/bazel/_bazel_nasfarley88/c06b69b14aa56b339da9c44f7a52da1e/external/python/python /media/usb/anki-git/nasfarley88-cache/bazel/_
bazel_nasfarley88/c06b69b14aa56b339da9c44f7a52da1e/external/com_github_ali5h_rules_pip/third_party/py/pip/_vendor/pep517/_in_process.py prepare_metadata_for_build_wheel /tmp/tmpl99wxtjo Check the logs for full c
ommand output.
Traceback (most recent call last):
  File "/media/usb/anki-git/pip/pyqt5/install_pyqt5.py", line 163, in <module>
    main()
  File "/media/usb/anki-git/pip/pyqt5/install_pyqt5.py", line 119, in main
    _pkg = install_package(with_version, folder, [])
  File "/media/usb/anki-git/pip/pyqt5/install_pyqt5.py", line 54, in install_package
    dist_info = glob.glob(os.path.join(directory, "*.dist-info"))[0]
IndexError: list index out of range
)
ERROR: Analysis of target '//:dist' failed; build aborted: Analysis failed
INFO: Elapsed time: 13.609s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded, 0 targets configured)
nasfarley88@wesley /m/u/anki-git (master) [1]>

This file was present in ./bazel/_bazel_nasfarley88/c06b69b14aa56b339da9c44f7a52da1e/external/pyqt5/PyQt5/bindings/QtCore/QtCoremod.sip but I couldn’t figure out if this was the right file and/or how to hook it up

Ah, looks like you won’t be able to just skip pyqt5, as it’s required for building the UI files.

The following patch should allow you to point at your local PyQt5 installation - adjust local_pyqt_path to the correct site-packages location on your machine.

diff --git a/pip/pyqt5/install_pyqt5.py b/pip/pyqt5/install_pyqt5.py
index 89b842fcf..9bb68764e 100644
--- a/pip/pyqt5/install_pyqt5.py
+++ b/pip/pyqt5/install_pyqt5.py
@@ -9,6 +9,7 @@ import os
 import shutil
 import sys
 import re
+import subprocess

 from pip._internal.commands import create_command
 from pip._vendor import pkg_resources
@@ -107,19 +108,36 @@ def merge_files(root, source):
 def main():
     base = sys.argv[1]

-    packages = [
-       ("pyqt5", "pyqt5==5.15.2"),
-       ("pyqtwebengine", "pyqtwebengine==5.15.2"),
-       ("pyqt5-sip", "pyqt5_sip==12.8.1"),
-    ]
-
-    for (name, with_version) in packages:
-        # install package in subfolder
-        folder = os.path.join(base, "temp")
-        _pkg = install_package(with_version, folder, [])
-        # merge into parent
-        merge_files(base, folder)
-        shutil.rmtree(folder)
+    local_pyqt_path = os.path.expanduser("~/Local/py514/lib/python3.8/site-packages/")
+    if local_pyqt_path:
+        subprocess.run(
+            [
+                "rsync",
+                "-ai",
+                "--include=PyQt**",
+                "--exclude=*",
+                local_pyqt_path,
+                base + "/",
+            ],
+            check=True,
+        )
+        with open(os.path.join(base, "__init__.py"), "w") as file:
+            pass
+
+    else:
+        packages = [
+            ("pyqt5", "pyqt5==5.15.2"),
+            ("pyqtwebengine", "pyqtwebengine==5.15.2"),
+            ("pyqt5-sip", "pyqt5_sip==12.8.1"),
+        ]
+
+        for (name, with_version) in packages:
+            # install package in subfolder
+            folder = os.path.join(base, "temp")
+            _pkg = install_package(with_version, folder, [])
+            # merge into parent
+            merge_files(base, folder)
+            shutil.rmtree(folder)

     # add missing py.typed file
     with open(os.path.join(base, "py.typed"), "w") as file:

The patch worked a treat for pylib (once changing the path to /usr/lib/python3/dist-packages/) but this surfaced more errors with rust below (truncated for brevity, they were all ‘use of unstable library feature’ errors for what look like standard library errors)

nasfarley88@wesley /m/u/anki-git (master)> ./scripts/build                                               
INFO: Analyzed target //:dist (585 packages loaded, 15716 targets configured).
INFO: Found 1 target...                                                                                                                                                                                            
INFO: From Compiling Rust lib utime v0.3.1 (2 files):
error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
  --> external/raze__utime__0_3_1/src/lib.rs:22:1                                                        
   |                                                
22 | extern crate libc;                                                                                                                                                                                            
   | ^^^^^^^^^^^^^^^^^^                                                                                  
   |
   = note: see issue #27812 <https://github.com/rust-lang/rust/issues/27812> for more information                                                                                                                  
                                                    
error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
  --> external/raze__utime__0_3_1/src/lib.rs:46:21                                                       
   |                                                
46 |         let atime = timeval {                                                                                                                                                                                 
   |                     ^^^^^^^                                                                         
   |
   = note: see issue #27812 <https://github.com/rust-lang/rust/issues/27812> for more information                                                                                                                  
                                                                                                         
error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
  --> external/raze__utime__0_3_1/src/lib.rs:47:30                                                       
   |                                                
47 |             tv_sec: atime as time_t,                                                                                                                                                                          
   |                              ^^^^^^                                                                 
   |
   = note: see issue #27812 <https://github.com/rust-lang/rust/issues/27812> for more information
                                                    
error[E0658]: use of unstable library feature 'rustc_private': this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via `Cargo.toml` instead?
  --> external/raze__utime__0_3_1/src/lib.rs:50:21                                                                                                                                                                    |                                                
50 |         let mtime = timeval {                                                                                                                                                                                 
   |                     ^^^^^^^                  
   |                                                                                                     
   = note: see issue #27812 <https://github.com/rust-lang/rust/issues/27812> for more information

Any pointers on what to look for/change would be greatly appreciated

Adding the platform to /Cargo.toml and running update.py in the /cargo folder may fix it.

I’ve pushed the required change to git, and you can discard the above patch, and add the following to user.bazelrc in the project folder root:

build --action_env=PYTHON_SITE_PACKAGES=/path/to/site/packages

Much closer this time with the latest master; updating the user.bazelrc worked great. Just a few rust compile errors after cleaning the bazel cache and running the build script again:

nasfarley88@wesley /m/u/anki-git (master)> ./scripts/build
2020/12/30 09:24:34 Downloading https://releases.bazel.build/3.7.0/release/bazel-3.7.0-linux-arm64...
Extracting Bazel installation...
Starting local Bazel server and connecting to it...
WARNING: Download from https://mirror.bazel.build/nodejs.org/dist/v12.13.0/node-v12.13.0-linux-arm64.tar.xz failed: class com.google.devtools.build.lib.bazel.repository.downloader.UnrecoverableHttpException GET
returned 404 Not Found
INFO: Analyzed target //:dist (590 packages loaded, 15864 targets configured).
INFO: Found 1 target...
INFO: From CargoBuildScriptRun external/raze__crossbeam_utils__0_7_2/crossbeam_utils_build_script.out_dir:
error[E0658]: use of unstable library feature 'integer_atomics'
 --> <anon>:1:18
  |
1 | pub type Probe = core::sync::atomic::AtomicU128;
  |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #32976 <https://github.com/rust-lang/rust/issues/32976> for more information

error: aborting due to previous error

For more information about this error, try `rustc --explain E0658`.
INFO: From CargoBuildScriptRun external/raze__openssl_sys__0_9_60/openssl_sys_build_script.out_dir:
AARCH64_UNKNOWN_LINUX_GNU_OPENSSL_LIB_DIR unset
OPENSSL_LIB_DIR unset
AARCH64_UNKNOWN_LINUX_GNU_OPENSSL_INCLUDE_DIR unset
OPENSSL_INCLUDE_DIR unset
AARCH64_UNKNOWN_LINUX_GNU_OPENSSL_DIR unset
OPENSSL_DIR unset
OPT_LEVEL = Some("3")
TARGET = Some("aarch64-unknown-linux-gnu")
HOST = Some("aarch64-unknown-linux-gnu")
CC_aarch64-unknown-linux-gnu = None
CC_aarch64_unknown_linux_gnu = None
HOST_CC = None
CC = Some("/usr/bin/gcc")
CFLAGS_aarch64-unknown-linux-gnu = None
CFLAGS_aarch64_unknown_linux_gnu = None
HOST_CFLAGS = None
CFLAGS = None
CRATE_CC_NO_DEFAULTS = None
DEBUG = None
CARGO_CFG_TARGET_FEATURE = None
running: "/usr/bin/gcc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-I" "/usr/include" "-Wall" "-Wextra" "-E" "build/expando.c"
exit code: 0
INFO: From CargoBuildScriptRun external/raze__httparse__1_3_4/httparse_build_script.out_dir:
Build Script Warning: CARGO_CFG_TARGET_FEATURE was not set

INFO: From CargoBuildScriptRun external/raze__libsqlite3_sys__0_20_1/libsqlite3_sys_build_script.out_dir:
TARGET = Some("aarch64-unknown-linux-gnu")
OPT_LEVEL = Some("3")
HOST = Some("aarch64-unknown-linux-gnu")
CC_aarch64-unknown-linux-gnu = None
CC_aarch64_unknown_linux_gnu = None
HOST_CC = None
CC = Some("/usr/bin/gcc")
CFLAGS_aarch64-unknown-linux-gnu = None
CFLAGS_aarch64_unknown_linux_gnu = None
HOST_CFLAGS = None
CFLAGS = None
CRATE_CC_NO_DEFAULTS = None
DEBUG = None
CARGO_CFG_TARGET_FEATURE = None
running: "/usr/bin/gcc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-DSQLITE_CORE" "-DSQLITE_DEFAULT_FOREIGN_KEYS=1" "-DSQLITE_ENABLE_API_ARMOR" "-DSQLITE_ENABLE_COLUMN_METADATA" "-DSQLITE_ENABLE_DBST
AT_VTAB" "-DSQLITE_ENABLE_FTS3" "-DSQLITE_ENABLE_FTS3_PARENTHESIS" "-DSQLITE_ENABLE_FTS5" "-DSQLITE_ENABLE_JSON1" "-DSQLITE_ENABLE_LOAD_EXTENSION=1" "-DSQLITE_ENABLE_MEMORY_MANAGEMENT" "-DSQLITE_ENABLE_RTREE" "-
DSQLITE_ENABLE_STAT2" "-DSQLITE_ENABLE_STAT4" "-DSQLITE_SOUNDEX" "-DSQLITE_THREADSAFE=1" "-DSQLITE_USE_URI" "-DHAVE_USLEEP=1" "-D_POSIX_THREAD_SAFE_FUNCTIONS" "-DHAVE_ISNAN" "-DHAVE_LOCALTIME_R" "-o" "/media/usb
/nasfarley88-cache/bazel/_bazel_nasfarley88/c06b69b14aa56b339da9c44f7a52da1e/sandbox/linux-sandbox/163/execroot/net_ankiweb_anki/bazel-out/aarch64-opt/bin/external/raze__libsqlite3_sys__0_20_1/libsqlite3_sys_bui
ld_script.out_dir/sqlite3/sqlite3.o" "-c" "sqlite3/sqlite3.c"
exit code: 0
AR_aarch64-unknown-linux-gnu = None
AR_aarch64_unknown_linux_gnu = None
HOST_AR = None
AR = Some("/usr/bin/ar")
running: "/usr/bin/ar" "cq" "/media/usb/nasfarley88-cache/bazel/_bazel_nasfarley88/c06b69b14aa56b339da9c44f7a52da1e/sandbox/linux-sandbox/163/execroot/net_ankiweb_anki/bazel-out/aarch64-opt/bin/external/raze__li
bsqlite3_sys__0_20_1/libsqlite3_sys_build_script.out_dir/libsqlite3.a" "/media/usb/nasfarley88-cache/bazel/_bazel_nasfarley88/c06b69b14aa56b339da9c44f7a52da1e/sandbox/linux-sandbox/163/execroot/net_ankiweb_anki/
bazel-out/aarch64-opt/bin/external/raze__libsqlite3_sys__0_20_1/libsqlite3_sys_build_script.out_dir/sqlite3/sqlite3.o"
exit code: 0
running: "/usr/bin/ar" "s" "/media/usb/nasfarley88-cache/bazel/_bazel_nasfarley88/c06b69b14aa56b339da9c44f7a52da1e/sandbox/linux-sandbox/163/execroot/net_ankiweb_anki/bazel-out/aarch64-opt/bin/external/raze__lib
sqlite3_sys__0_20_1/libsqlite3_sys_build_script.out_dir/libsqlite3.a"
exit code: 0
INFO: From CargoBuildScriptRun external/raze__openssl_sys__0_9_60/openssl_sys_build_script.out_dir:
AARCH64_UNKNOWN_LINUX_GNU_OPENSSL_LIB_DIR unset
OPENSSL_LIB_DIR unset
AARCH64_UNKNOWN_LINUX_GNU_OPENSSL_INCLUDE_DIR unset
OPENSSL_INCLUDE_DIR unset
AARCH64_UNKNOWN_LINUX_GNU_OPENSSL_DIR unset
OPENSSL_DIR unset
OPT_LEVEL = Some("3")
TARGET = Some("aarch64-unknown-linux-gnu")
HOST = Some("aarch64-unknown-linux-gnu")
CC_aarch64-unknown-linux-gnu = None
CC_aarch64_unknown_linux_gnu = None
HOST_CC = None
CC = Some("/usr/bin/gcc")
CFLAGS_aarch64-unknown-linux-gnu = None
CFLAGS_aarch64_unknown_linux_gnu = None
HOST_CFLAGS = None
CFLAGS = None
CRATE_CC_NO_DEFAULTS = None
DEBUG = None
CARGO_CFG_TARGET_FEATURE = None
running: "/usr/bin/gcc" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-I" "/usr/include" "-Wall" "-Wextra" "-E" "build/expando.c"
exit code: 0
INFO: From Compiling Rust lib reqwest v0.10.8 (49 files):
error[E0463]: can't find crate for `lazy_static`
   --> external/raze__reqwest__0_10_8/src/lib.rs:286:5
    |
286 |     extern crate lazy_static;
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate

error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.
ERROR: /media/usb/nasfarley88-cache/bazel/_bazel_nasfarley88/c06b69b14aa56b339da9c44f7a52da1e/external/raze__reqwest__0_10_8/BUILD.bazel:54:13: output 'external/raze__reqwest__0_10_8/libreqwest-608794382.rlib' w
as not created
ERROR: /media/usb/nasfarley88-cache/bazel/_bazel_nasfarley88/c06b69b14aa56b339da9c44f7a52da1e/external/raze__reqwest__0_10_8/BUILD.bazel:54:13: not all outputs were created or valid
Target //:dist failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 1738.733s, Critical Path: 705.09s
INFO: 507 processes: 121 internal, 386 linux-sandbox.
FAILED: Build did NOT complete successfully

lazy_static is in the Cargo.lock and rslib/BUILD.bazel and various other places so I’m not sure why it can’t find the crate

Please try again with the latest git

It builds perfectly :tada:!

However, I’ve got problems building the wheel, buth with and without --system-site-packages in the virtualenv with the following error:

(env) nasfarley88@wesley /m/u/anki-git (master)> pip install --upgrade ./bazel-dist/aqt-2.1.39-py3-none-any.whl
Processing ./bazel-dist/aqt-2.1.39-py3-none-any.whl
Collecting flask_cors
  Using cached Flask_Cors-3.0.9-py2.py3-none-any.whl (14 kB)
Collecting pyqt5>=5.12
  Downloading PyQt5-5.15.2.tar.gz (3.3 MB)
     |████████████████████████████████| 3.3 MB 4.4 MB/s 
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... |
done
Collecting requests
  Using cached requests-2.25.1-py2.py3-none-any.whl (61 kB)
Collecting jsonschema
  Using cached jsonschema-3.2.0-py2.py3-none-any.whl (56 kB)
Collecting send2trash
  Using cached Send2Trash-1.5.0-py3-none-any.whl (12 kB)
Collecting pyqtwebengine
  Using cached PyQtWebEngine-5.15.2.tar.gz (48 kB)
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... error
    ERROR: Command errored out with exit status 1:
     command: /media/usb/anki-git/env/bin/python3 /tmp/tmpw4yg2b24 prepare_metadata_for_build_wheel /tmp/tmpaikxkxbw
         cwd: /tmp/pip-install-l08h7u_i/pyqtwebengine
    Complete output (6 lines):
    Querying qmake about your Qt installation...
    /usr/bin/qmake -query
    These bindings will be built: QtWebEngineCore, QtWebEngine, QtWebEngineWidgets.
    Generating the QtWebEngineCore bindings...
    tmpw4yg2b24: Unable to find file "QtCore/QtCoremod.sip"
    
    ----------------------------------------
ERROR: Command errored out with exit status 1: /media/usb/anki-git/env/bin/python3 /tmp/tmpw4yg2b24 prepare_metadata_for_build_wheel /tmp/tmpaikxkxbw Check the logs for full command output.

I’m not familiar with how wheels work; I would’ve thought that PyQt5 would not need to be downloaded since all the work was done by ./scripts/build? Especially with the --system-site-packages option.

Any pointers would be greatly appreciated

Installing without --upgrade on pip install installs properly, but then fails when anki starts with:

Error
An error occurred. Please use Tools > Check Database to see if that fixes the problem.
If problems persist, please report the problem on our support site. Please copy and paste the information below into your report.
Anki 2.1.39 (67191d33) Python 3.8.6 Qt 5.14.2 PyQt 5.15.0
Platform: Linux
Flags: frz=False ao=False sv=1
Add-ons, last update check: 2020-12-30 13:11:20

Caught exception:
Traceback (most recent call last):
  File "/media/usb/anki-git/env/lib/python3.8/site-packages/aqt/webview.py", line 35, in cmd
    return json.dumps(self.onCmd(str))
  File "/media/usb/anki-git/env/lib/python3.8/site-packages/aqt/webview.py", line 124, in _onCmd
    return self._onBridgeCmd(str)
  File "/media/usb/anki-git/env/lib/python3.8/site-packages/aqt/webview.py", line 551, in _onBridgeCmd
    if self._shouldIgnoreWebEvent():
  File "/media/usb/anki-git/env/lib/python3.8/site-packages/aqt/webview.py", line 544, in _shouldIgnoreWebEvent
    if sip.isdeleted(self):
TypeError: isdeleted() argument 1 must be sip.simplewrapper, not AnkiWebView

Caught exception:
Traceback (most recent call last):
  File "/media/usb/anki-git/env/lib/python3.8/site-packages/aqt/webview.py", line 35, in cmd
    return json.dumps(self.onCmd(str))
  File "/media/usb/anki-git/env/lib/python3.8/site-packages/aqt/webview.py", line 124, in _onCmd
    return self._onBridgeCmd(str)
  File "/media/usb/anki-git/env/lib/python3.8/site-packages/aqt/webview.py", line 551, in _onBridgeCmd
    if self._shouldIgnoreWebEvent():
  File "/media/usb/anki-git/env/lib/python3.8/site-packages/aqt/webview.py", line 544, in _shouldIgnoreWebEvent
    if sip.isdeleted(self):
TypeError: isdeleted() argument 1 must be sip.simplewrapper, not AnkiWebView

Caught exception:
Traceback (most recent call last):
  File "/media/usb/anki-git/env/lib/python3.8/site-packages/aqt/webview.py", line 35, in cmd
    return json.dumps(self.onCmd(str))
  File "/media/usb/anki-git/env/lib/python3.8/site-packages/aqt/webview.py", line 124, in _onCmd
    return self._onBridgeCmd(str)
  File "/media/usb/anki-git/env/lib/python3.8/site-packages/aqt/webview.py", line 551, in _onBridgeCmd
    if self._shouldIgnoreWebEvent():
  File "/media/usb/anki-git/env/lib/python3.8/site-packages/aqt/webview.py", line 544, in _shouldIgnoreWebEvent
    if sip.isdeleted(self):
TypeError: isdeleted() argument 1 must be sip.simplewrapper, not AnkiWebView

I can see that Qt and PyQt versions are different, but only minor versions.

This error also appears when trying to quit Anki (even when using ^C to interrupt, I was forced to use ^\ to quit)

Probably an issue with your sip, PyQt or PyQtWebEngine version. Make sure you’re not installing any of them from PyPI implicitly by removing the PyQt requirements from py_wheel() in qt/aqt/BUILD.bazel. This may be related: Change sip import by zjosua · Pull Request #762 · ankitects/anki · GitHub

I’ve removed them from the requirements, but still the same problem. The following are installed as system packages, are these the right versions?

python3-pyqt5.sip/groovy,now 12.8.0-1 arm64 [installed]
python3-pyqt5/groovy,now 5.15.0+dfsg-1 arm64 [installed]                                                 
python3-pyqt5.qtwebengine/groovy,now 5.15.0-1 arm64 [installed]

EDIT:

Looking at anki/BUILD.bazel at master · ankitects/anki · GitHub this might be too late a version; I suspect that sip may have had a major version change in the mean time. I’ll build an older Qt (5.14) and see if that fixes it

5.15 should work, and this looks like a PyQt issue rather than a Qt issue. I presume you get a similar error if you run the following and wait a few seconds?

import sys
from PyQt5.Qt import *
from PyQt5.QtWebEngineWidgets import *
from PyQt5.QtWidgets import QApplication
from PyQt5 import sip


class WrappedView(QWebEngineView):
    pass


app = QApplication(sys.argv)
web = WrappedView()
web.load(QUrl("http://example.com"))
web.show()


def on_timer():
    print(sip.isdeleted(web))


timer = QTimer()
timer.setSingleShot(True)
timer.timeout.connect(on_timer)
timer.start(2000)

sys.exit(app.exec_())

If so, this problem does not appear to be specific to Anki, and if importing sip directly does not help, maybe someone on the PyQt mailing list might have a suggestion.

Yeah, looks like it’s a PyQt5 packaging problem on Ubuntu. I’ll have a dig around. Thanks for your help!

sip, PyQt and PyQtWebEngine are not too hard to compile from source, so if your distro has Qt development packages, you could try removing its PyQt packages and building them yourself.

1 Like

Out of interest, how standalone is the anki build? If the build is a ‘static’ build, I could create a docker container that builds it’s own pyqt5 etc. and copy over the artefacts. (copying over a virtualenv from docker wouldn’t be a problem, but it I’m not sure how the python references the Qt libraries)

The build process creates wheels that can be copied around and installed into an existing Python environment. If you build PyQt wheels on one device, you can likely copy them to another device with the same architecture and use them there.