Anki build failed because Python 3.14 is installed on my system (in addition to Python 3.13)

I was trying to build Anki from source on Ubuntu and encountered an issue because I have python 3.14 installed on my system.

    Finished `release` profile [optimized] target(s) in 0.34s
failed: pyenv
Resolved 116 packages in 3ms
   Building orjson==3.10.18
  × Failed to build `orjson==3.10.18`
  ├─▶ The build backend returned an error
  ╰─▶ Call to `maturin.build_wheel` failed (exit status: 1)

      [stdout]
      Running `maturin pep517 build-wheel -i
      /home/user/.cache/uv/builds-v0/.tmp2C6lOS/bin/python --compatibility
      off`

      [stderr]
      📦 Including license file `LICENSE-APACHE`
      📦 Including license file `LICENSE-MIT`
      🍹 Building a mixed python/rust project
      🔗 Found pyo3-ffi bindings
      🐍 Found CPython 3.14 at
      /home/user/.cache/uv/builds-v0/.tmp2C6lOS/bin/python
         Compiling pyo3-build-config v0.23.3
      (/home/user/.cache/uv/sdists-v9/pypi/orjson/3.10.18/1cWAGf-KR0pyLjAQWJxy6/src/include/pyo3/pyo3-build-config)
         Compiling serde v1.0.219
         Compiling itoap v1.0.1
         Compiling xxhash-rust v0.8.15
         Compiling bytecount v0.6.8
         Compiling associative-cache v2.0.0
         Compiling uuid v1.16.0
         Compiling once_cell v1.21.3
         Compiling simdutf8 v0.1.5
         Compiling pyo3-ffi v0.23.3
      (/home/user/.cache/uv/sdists-v9/pypi/orjson/3.10.18/1cWAGf-KR0pyLjAQWJxy6/src/include/pyo3/pyo3-ffi)
         Compiling orjson v3.10.18
      (/home/user/.cache/uv/sdists-v9/pypi/orjson/3.10.18/1cWAGf-KR0pyLjAQWJxy6/src)
      error: failed to run custom build command for `pyo3-ffi v0.23.3
      (/home/user/.cache/uv/sdists-v9/pypi/orjson/3.10.18/1cWAGf-KR0pyLjAQWJxy6/src/include/pyo3/pyo3-ffi)`

      Caused by:
        process didn't exit successfully:
      `/home/user/GitHub/anki/out/rust/release/build/pyo3-ffi-35383e79d3a7ebd1/build-script-build`
      (exit status: 1)
        --- stdout
        cargo:rustc-check-cfg=cfg(Py_LIMITED_API)
        cargo:rustc-check-cfg=cfg(Py_GIL_DISABLED)
        cargo:rustc-check-cfg=cfg(PyPy)
        cargo:rustc-check-cfg=cfg(GraalPy)
        cargo:rustc-check-cfg=cfg(py_sys_config, values("Py_DEBUG",
      "Py_REF_DEBUG", "Py_TRACE_REFS", "COUNT_ALLOCS"))
        cargo:rustc-check-cfg=cfg(invalid_from_utf8_lint)
        cargo:rustc-check-cfg=cfg(pyo3_disable_reference_pool)
        cargo:rustc-check-cfg=cfg(pyo3_leak_on_drop_without_reference_pool)
        cargo:rustc-check-cfg=cfg(diagnostic_namespace)
        cargo:rustc-check-cfg=cfg(c_str_lit)
        cargo:rustc-check-cfg=cfg(rustc_has_once_lock)
        cargo:rustc-check-cfg=cfg(io_error_more)
        cargo:rustc-check-cfg=cfg(fn_ptr_eq)
        cargo:rustc-check-cfg=cfg(Py_3_7)
        cargo:rustc-check-cfg=cfg(Py_3_8)
        cargo:rustc-check-cfg=cfg(Py_3_9)
        cargo:rustc-check-cfg=cfg(Py_3_10)
        cargo:rustc-check-cfg=cfg(Py_3_11)
        cargo:rustc-check-cfg=cfg(Py_3_12)
        cargo:rustc-check-cfg=cfg(Py_3_13)
        cargo:rerun-if-env-changed=PYO3_CROSS
        cargo:rerun-if-env-changed=PYO3_CROSS_LIB_DIR
        cargo:rerun-if-env-changed=PYO3_CROSS_PYTHON_VERSION
        cargo:rerun-if-env-changed=PYO3_CROSS_PYTHON_IMPLEMENTATION
        cargo:rerun-if-env-changed=PYO3_PRINT_CONFIG
        cargo:rerun-if-env-changed=PYO3_USE_ABI3_FORWARD_COMPATIBILITY

        --- stderr
        error: the configured Python interpreter version (3.14) is newer than
      PyO3's maximum supported version (3.13)
        = help: please check if an updated version of PyO3 is available.
      Current version: 0.23.3
        = help: set PYO3_USE_ABI3_FORWARD_COMPATIBILITY=1 to suppress this
      check and build anyway using the stable ABI
      warning: build failed, waiting for other jobs to finish...
      💥 maturin failed
        Caused by: Failed to build a native library through cargo
        Caused by: Cargo build finished with "exit status:
      101": `env -u CARGO PYO3_BUILD_EXTENSION_MODULE="1"
      PYO3_ENVIRONMENT_SIGNATURE="cpython-3.14-64bit"
      PYO3_PYTHON="/home/user/.cache/uv/builds-v0/.tmp2C6lOS/bin/python"
      PYTHON_SYS_EXECUTABLE="/home/user/.cache/uv/builds-v0/.tmp2C6lOS/bin/python"
      "cargo" "rustc" "--profile" "release" "--message-format"
      "json-render-diagnostics" "--manifest-path"
      "/home/user/.cache/uv/sdists-v9/pypi/orjson/3.10.18/1cWAGf-KR0pyLjAQWJxy6/src/Cargo.toml"
      "--lib"`
      Error: command ['maturin', 'pep517', 'build-wheel', '-i',
      '/home/user/.cache/uv/builds-v0/.tmp2C6lOS/bin/python',
      '--compatibility', 'off'] returned non-zero exit status 1

      hint: This usually indicates a problem with the package or the build
      environment.
  help: `orjson` (v3.10.18) was included because `anki` depends on `orjson`
Failed to run (1): /home/user/GitHub/anki/out/extracted/uv/uv sync --locked --no-config --all-packages --extra qt --extra audio

Build failed.

Here’s the output of some relevant commands:

which python
/usr/bin/python

python --version
Python 3.13.7

which python3
/home/linuxbrew/.linuxbrew/bin/python3

python3 --version
Python 3.14.0

I solved the issue by uninstalling python 3.14. But, I wonder if there’s a better solution. Also, can the build script of Anki be adjusted so that it can fall back to a supported Python version if a newer Python is also installed on the user’s computer?

help: set PYO3_USE_ABI3_FORWARD_COMPATIBILITY=1 to suppress this

I tried this and got:

user@Ubuntu:~/GitHub/anki$ PYO3_USE_ABI3_FORWARD_COMPATIBILITY=1 ./run
    Finished `release` profile [optimized] target(s) in 0.75s
failed: pyenv
Resolved 116 packages in 6ms
   Building orjson==3.10.18
  × Failed to build `orjson==3.10.18`
  ├─▶ The build backend returned an error
  ╰─▶ Call to `maturin.build_wheel` failed (exit status: 1)

      [stdout]
      Running `maturin pep517 build-wheel -i
      /home/user/.cache/uv/builds-v0/.tmpB3bHoF/bin/python --compatibility
      off`

      [stderr]
          Blocking waiting for file lock on package cache
      📦 Including license file `LICENSE-APACHE`
      📦 Including license file `LICENSE-MIT`
      🍹 Building a mixed python/rust project
      🔗 Found pyo3-ffi bindings
      🐍 Found CPython 3.14 at
      /home/user/.cache/uv/builds-v0/.tmpB3bHoF/bin/python
         Compiling pyo3-build-config v0.23.3
      (/home/user/.cache/uv/sdists-v9/pypi/orjson/3.10.18/1cWAGf-KR0pyLjAQWJxy6/src/include/pyo3/pyo3-build-config)
         Compiling pyo3-ffi v0.23.3
      (/home/user/.cache/uv/sdists-v9/pypi/orjson/3.10.18/1cWAGf-KR0pyLjAQWJxy6/src/include/pyo3/pyo3-ffi)
         Compiling orjson v3.10.18
      (/home/user/.cache/uv/sdists-v9/pypi/orjson/3.10.18/1cWAGf-KR0pyLjAQWJxy6/src)
      error[E0412]: cannot find type `c_void` in this scope
        --> include/pyo3/pyo3-ffi/src/pyhash.rs:19:38
         |
      19 |     pub fn Py_HashBuffer(ptr: *const c_void, len: Py_ssize_t) ->
      Py_hash_t;
         |                                      ^^^^^^ not found in this scope
         |
      note: found an item that was configured out
        --> include/pyo3/pyo3-ffi/src/pyhash.rs:6:19
         |
       5 | #[cfg(not(any(Py_LIMITED_API, PyPy)))]
         |          --------------------------- the item is gated here
       6 | use std::os::raw::c_void;
         |                   ^^^^^^
      help: consider importing one of these items
         |
       8 + use std::ffi::c_void;
         |
       8 + use std::os::raw::c_void;
         |
       8 + use core::ffi::c_void;
         |
       8 + use libc::c_void;
         |

      error[E0412]: cannot find type `Py_ssize_t` in this scope
        --> include/pyo3/pyo3-ffi/src/pyhash.rs:19:51
         |
      19 |     pub fn Py_HashBuffer(ptr: *const c_void, len: Py_ssize_t) ->
      Py_hash_t;
         |                                                   ^^^^^^^^^^ not
      found in this scope
         |
      note: found an item that was configured out
        --> include/pyo3/pyo3-ffi/src/pyhash.rs:2:32
         |
       1 | #[cfg(not(any(Py_LIMITED_API, PyPy)))]
         |          --------------------------- the item is gated here
       2 | use crate::pyport::{Py_hash_t, Py_ssize_t};
         |                                ^^^^^^^^^^
      help: consider importing this type alias through its public re-export
         |
       8 + use crate::Py_ssize_t;
         |

      error[E0412]: cannot find type `Py_hash_t` in this scope
        --> include/pyo3/pyo3-ffi/src/pyhash.rs:19:66
         |
      19 |     pub fn Py_HashBuffer(ptr: *const c_void, len: Py_ssize_t) ->
      Py_hash_t;
         |
      ^^^^^^^^^ not found in this scope
         |
      note: found an item that was configured out
        --> include/pyo3/pyo3-ffi/src/pyhash.rs:2:21
         |
       1 | #[cfg(not(any(Py_LIMITED_API, PyPy)))]
         |          --------------------------- the item is gated here
       2 | use crate::pyport::{Py_hash_t, Py_ssize_t};
         |                     ^^^^^^^^^
      note: found an item that was configured out
        --> include/pyo3/pyo3-ffi/src/setobject.rs:3:20
         |
       2 | #[cfg(not(any(Py_LIMITED_API, PyPy, GraalPy)))]
         |          ------------------------------------ the item is gated
      here
       3 | use crate::pyport::Py_hash_t;
         |                    ^^^^^^^^^
      help: consider importing this type alias through its public re-export
         |
       8 + use crate::Py_hash_t;
         |

      For more information about this error, try `rustc --explain E0412`.
      error: could not compile `pyo3-ffi` (lib) due to 3 previous errors
      warning: build failed, waiting for other jobs to finish...
      💥 maturin failed
        Caused by: Failed to build a native library through cargo
        Caused by: Cargo build finished with "exit status:
      101": `env -u CARGO PYO3_BUILD_EXTENSION_MODULE="1"
      PYO3_ENVIRONMENT_SIGNATURE="cpython-3.14-64bit"
      PYO3_PYTHON="/home/user/.cache/uv/builds-v0/.tmpB3bHoF/bin/python"
      PYTHON_SYS_EXECUTABLE="/home/user/.cache/uv/builds-v0/.tmpB3bHoF/bin/python"
      "cargo" "rustc" "--profile" "release" "--message-format"
      "json-render-diagnostics" "--manifest-path"
      "/home/user/.cache/uv/sdists-v9/pypi/orjson/3.10.18/1cWAGf-KR0pyLjAQWJxy6/src/Cargo.toml"
      "--lib"`
      Error: command ['maturin', 'pep517', 'build-wheel', '-i',
      '/home/user/.cache/uv/builds-v0/.tmpB3bHoF/bin/python',
      '--compatibility', 'off'] returned non-zero exit status 1

      hint: This usually indicates a problem with the package or the build
      environment.
  help: `orjson` (v3.10.18) was included because `anki` depends on `orjson`
Failed to run (1): /home/user/GitHub/anki/out/extracted/uv/uv sync --locked --no-config --all-packages --extra qt --extra audio

Build failed.

Interestingly, the error message says:

  Current version: 0.23.3

But, cargo.lock says 0.25.1

user@Ubuntu:~/GitHub/anki$ grep -A 4 'pyo3' Cargo.lock
name = "pyo3"
version = "0.25.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8970a78afe0628a3e3430376fc5fd76b6b45c4d43360ffd6cdd40bdde72b682a"
dependencies = [
--
name = "pyo3-ffi"
version = "0.25.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7114fe5457c61b276ab77c5055f206295b812608083644a5c5b2640c3102565c"
dependencies = [

uv might be ignoring .python-version due to the --no-config flag added in set UV_PYTHON_DOWNLOADS=auto when doing `uv sync` by Grinkers · Pull Request #4191 · ankitects/anki · GitHub

DEBUG uv 0.7.13
DEBUG Found project root: `/anki`
DEBUG Found workspace root: `/anki`
DEBUG Adding root workspace member: `/anki`
DEBUG Adding discovered workspace member: `/anki/pylib`
DEBUG Adding discovered workspace member: `/anki/qt`
DEBUG Acquired lock for `/anki`
DEBUG Ignoring Python version file at `.python-version` due to `--no-config`
DEBUG Using Python request `>=3.9` from `requires-python` metadata
DEBUG Checking for Python environment at `out/pyenv`
...

I’m not sure why that flag was added though, probably to solve another issue

The error message is from maturin’s invocation of cargo, not anki’s

1 Like

Would something like this work?

diff --git a/pylib/pyproject.toml b/pylib/pyproject.toml
index fb7422694..b72913837 100644
--- a/pylib/pyproject.toml
+++ b/pylib/pyproject.toml
@@ -1,7 +1,7 @@
 [project]
 name = "anki"
 dynamic = ["version"]
-requires-python = ">=3.9"
+requires-python = ">=3.9, <3.14"
 license = "AGPL-3.0-or-later"
 dependencies = [
   "decorator",

I tried this and then ran ./run and got:

user@Ubuntu:~/GitHub/anki$ ./run
    Finished `release` profile [optimized] target(s) in 1.54s
failed: pyenv
Using CPython 3.13.9 interpreter at: /home/linuxbrew/.linuxbrew/opt/python@3.13/bin/python3.13
Removed virtual environment at: out/pyenv
Creating virtual environment at: out/pyenv
Resolved 116 packages in 8.85s
error: The lockfile at `uv.lock` needs to be updated, but `--locked` was provided. To update the lockfile, run `uv lock`.
Failed to run (2): /home/user/GitHub/anki/out/extracted/uv/uv sync --locked --no-config --all-packages --extra qt --extra audio

Build failed.

As advised, I ran uv lock and then ./run and got another error. I believe I have made some mistake in running the uv command.

user@Ubuntu:~/GitHub/anki$ uv lock
Using CPython 3.13.5
Resolved 116 packages in 663ms
user@Ubuntu:~/GitHub/anki$ ./run
    Finished `release` profile [optimized] target(s) in 0.29s
n2: ran 7 tasks, now up to date

Build succeeded in 3.38s.
Traceback (most recent call last):
  File "/home/user/GitHub/anki/tools/run.py", line 9, in <module>
    import aqt
  File "/home/user/GitHub/anki/qt/aqt/__init__.py", line 59, in <module>
    import anki.lang
  File "/home/user/GitHub/anki/pylib/anki/lang.py", line 13, in <module>
    import anki._backend
  File "/home/user/GitHub/anki/pylib/anki/_backend.py", line 18, in <module>
    from anki._backend_generated import RustBackendGenerated
ModuleNotFoundError: No module named 'anki._backend_generated'

Opened a pr that should fix this: fix(build): respect .python-version when generating pyenv by iamllama · Pull Request #4436 · ankitects/anki · GitHub

Not sure how that happened to be honest, but something similiar’s happened before (Feat/Svelte port for reviewer by Luc-Mcgrady · Pull Request #4289 · ankitects/anki · GitHub) so there’s probably another bug somewhere in the build system

2 Likes

Thanks for the fix. I applied this patch and used rm -rf out and then ran ./run. But, I got the following error.

Build succeeded in 906.84s.
Starting Anki 25.09.2...
Qt warning: Failed to create wl_display (No such file or directory)
Qt info: Could not load the Qt platform plugin "wayland" in "" even though it was found.
Qt warning: From 6.5.0, xcb-cursor0 or libxcb-cursor0 is needed to load the Qt xcb platform plugin.
Qt info: Could not load the Qt platform plugin "xcb" in "" even though it was found.
Qt fatal: This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: eglfs, wayland, minimalegl, offscreen, xcb, wayland-egl, minimal, vkkhrdisplay, vnc, linuxfb.

./run: line 20: 19592 Aborted                 ${PYENV}/bin/python tools/run.py $*

I have also tried deleting my local repo and cloning it again. It still fails.

Try getting libxcb-cursor0 via sudo apt install libxcb-cursor0

This doesn’t make any difference. I get the same error even after installing libxcb-cursor0

I can reliably reproduce it by running rm -rf out/pyenv, rm -rf out/pylib and rm -rf out/pycache sequentially and then ./run. I did this in an attempt to trigger rebuilding of the pyenv (after making some changes like uninstalling python 3.14 system-wide, etc.). It seems that running rm -rf out is better, but it causes all the rust packages to be recompiled on the next run, which takes time. So, is there any better solution?

Try the steps listed in anki/docs/linux.md at main · ankitects/anki · GitHub, there may be more libraries required that you’re missing

As I said in my original post, I was able to successfully run Anki from source code after uninstalling python 3.14. So, I don’t think that missing libraries are a problem.

This issue was fixed by restarting my WSL instance with wsl --shutdown in cmd.exe.

I have verified that the original issue (of not being able to compile with 3.14 installed on the system) was fixed by your PR. Thanks!

I think i understand why this is happening (cargo’s build system is superseding what ninja tells it to do), will look into fixing it.

EDIT: fix(build): make proto/i18n's implicit outputs explicit by iamllama · Pull Request #4439 · ankitects/anki · GitHub

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.