Hi, I’m trying to build Anki from source but I keep running into this error:
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.
Evandro reported and fixed it in Makefile a while ago and I’m not sure why it’d appear again.
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.
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.
I’ve just been spending the last few hours on this, with no luck
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 ಠ_ಠ).
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.
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:
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…
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.
That isn’t the case, which you can verify by taking a look here and here
I think that is a good point. Maybe you can submit a PR with those additions? I think a simple note mentioning that Anki configures the virtual env for you would be helpful!
While not covered in detail, it is mentioned in README.development that one must have Python 3.7+ installed. That being said, it is a bit confusing since /usr/bin/python isn’t available on 20.04. I didn’t know that! Check this out:
Remaining packages in Ubuntu which require Python 2.7 have been updated to use /usr/bin/python2 as their interpreter, and /usr/bin/python is not present by default on any new installs. On systems upgraded from previous releases, /usr/bin/python will continue to point to python2 for compatibility. Users who require /usr/bin/python for compatibility on newly-installed systems are encouraged to install the python-is-python3 package, for a /usr/bin/python pointing to python3 instead.
I would strongly advise against this method of configuring Python. While I definitely commend your persistent efforts , that is not a sustainable solution. I would try following the instructions from the Ubuntu wiki I linked to above.
On Ubuntu 18.04, I had to follow instructions similar to those here.
I’m getting a 404 for the first link, and in the second link a search for maturin only finds the comment #https://github.com/PyO3/maturin/issues/283 - Expected python to be a python interpreter inside a virtualenv. Sorry if I am missing something obvious. I imagine it’s been updated since you wrote the post?
Many thanks for the reference, it’s super useful to know about the python-is-python3 package! I imagine, though, that others in my situation might also not know about it?