Anki Forums

Build fails: python interpreter not inside a virtualenv?

Hi, I’m trying to build Anki from source but I keep running into this error:

maturin failed
Caused by: Expected `python` to be a python interpreter inside a virtualenv ಠ_ಠ

The python interpreter specified in my path is inside a virtual environment I’ve created using venv. I’ve tried different environments and Python installations but the result is the same (or another error, even earlier in the building process).
Does anybody have an idea what could be causing this? What special environment set-up is Anki expecting?
I would be grateful for any input.

I can’t seem to reproduce the issue with Cygwin and the latest master. Maybe try Git for Windows instead of Cygwin.

C:\>uname -s

Evandro reported and fixed it in Makefile a while ago and I’m not sure why it’d appear again.

  1. Only now I had run for the first the the make build command (on Windows), and I figure out it was not working due this problem (PyO3/maturin#283 - Expected python to be a python interpreter inside a virtualenv). Then, to fix it I had to manually edit the anki/pyenv/Scripts/activate script. Also, I am not sure why, but the Python interpreter on the GitHub Actions Windows was create the file anki/pyenv/Scripts/activate with CRLF line endings, which I had to convert to LF, other the shell script would never be sourced.

    "${PYTHON_BIN}" -m venv pyenv && \
    case "$$(uname -s)" in CYGWIN*|MINGW*|MSYS*) \
        dos2unix "${ACTIVATE_SCRIPT}" && \
        sed -i -- "s@VIRTUAL_ENV=\".*\"@VIRTUAL_ENV=\"$$(pwd)/pyenv\"@g" "${ACTIVATE_SCRIPT}"; \
        ;; esac && \
    . "${ACTIVATE_SCRIPT}" && \

I was mainly trying MinGW and cmd, I had also given Cygwin a shot.
But what can I say… After reading your answer I tried Cygwin one more time and it worked! I must have done something else wrong when I last tried it.
Still the same error message with other consoles, though.
My bash skills are close to non-existent, but if someone else wants to investigate the issue, I can give further information.

For now, I’m just happy that I can finally build Anki. Thanks a lot, @kelciour. :grinning:

I’m getting this error too, on Ubuntu 20.04, as well after setting up a virtual environment with venv

I’ve just been spending the last few hours on this, with no luck :frowning_face:
I tried using venv with ‘env’, also with ‘pyenv’ as I see the scripts using. Now I tried with pyenv and I still get the same error (maturin failed Caused by: Expected python to be a python interpreter inside a virtualenv ಠ_ಠ).

Any ideas?

I haven’t looked into this in super great detail, but here is my impression: because of the way that Anki’s build system bootstraps its own virtual environment, trying to build Anki with an activated virtual environment seems to be problematic. Activating a virtual environment before building Anki with ./run or make build can cause problems; I think this is because it will then try to create a virtual environment within a virtual environment.

I suggest running make clean and perhaps even rm -r pyenv to remove the virtual environment created by Anki’s build scripts, then deactivate your virtual environment or start a new shell session. As long as you have the required python version installed and in your PATH (re: README.development), you should be able to build Anki with ./run. This might seem scary, but Anki will bootstrap its own python virtual environment and will not pollute your global python environment, so no worries there.


As I wrote above, the trick for me was to run make run -B in Cygwin. But that would also only work if I had deleted the pyenv folder before (after a failed build) or I would still get the error.

1 Like

Thank you for your reply, Andrew. I tried that, too, but I don’t know how to get it to work, because Ubuntu doesn’t have an executable called python, only python3. I tried to create a function and export it:

python() {
	python3 "$@"
export -f python

That does work correctly, because if I type python I get to the python3 interactive shell (which doesn’t happen without this function), but when running run or make run I just get back to the initial error, Expected python to be a python interpreter inside a virtualenv ಠ_ಠ).

At this point I’m a bit at a loss how to move forward…

And if I delete the pyenv folder it first downloads pip, and then setuptools, then pyqt5, then pyqtwebengine, then PyQt5-sip, and then fails with /bin/bash: maturin: command not found.

If now I try to:

source pyenv/bin/activate
pip install maturin

then it finally works! Gosh, that was complicated :woozy_face:

So it seems that maturin isn’t correctly mentioned as a dependency? Also, it sounds important to mention in the build instructions to not use a virtual env for pythong doing it, and to tell Ubuntu users how to overcome the lack of a python executable.